Пример #1
0
    def test_sync_info_args_and_file_are_exclusive(self):
        """
        Test sync info args -s, -d and -f are mutually exclusive.
        """
        cmd = "-M model -V vendor -s /src -d /dst -f file".split(" ")
        args = self.parser.parse_args(cmd)

        with self.assertRaises(ArgumentError) as exc:
            cli.parse_sync_info(args)

        self.assertEqual(
            str(exc.exception),
            "Source (-s) and destination (-d) cannot be set when syncing "
            "from file (-f).",
        )
Пример #2
0
    def test_sync_info_missing(self):
        """
        Test mising sync info raises `ArgumentError`.
        """
        cmd = "-M model -V vendor".split(" ")
        args = self.parser.parse_args(cmd)

        with self.assertRaises(ArgumentError) as exc:
            cli.parse_sync_info(args)

        self.assertEqual(
            str(exc.exception),
            "Either sync mapping file (-f) or source (-s) and destination "
            "(-d) must be defined.",
        )
Пример #3
0
    def test_sync_info_args(self):
        """
        Test sync info is taken from -s and -d args.
        """
        cmd = "-M model -V vendor -s /src -d /dst".split(" ")
        args = self.parser.parse_args(cmd)

        sources, destinations = cli.parse_sync_info(args)

        self.assertEqual(sources, ["/src"])
        self.assertEqual(destinations, ["/dst"])
Пример #4
0
    def test_sync_info_file_incorrect_format(self):
        """
        Test incorrect mapping file format is reported.
        """
        with tempfile.TemporaryDirectory() as tmp_dir:
            mapping_file = os.path.join(tmp_dir, "incorrect.txt")
            with open(mapping_file, "w") as f:
                f.write("""\n/no/destination/set""")

            cmd = "-M model -V vendor -f {}".format(mapping_file).split(" ")
            args = self.parser.parse_args(cmd)

            with self.assertRaises(MappingFileException) as exc:
                cli.parse_sync_info(args)

            self.assertEqual(
                str(exc.exception),
                'Please separate source and destinationwith "==>".\n'
                'Problematic line: "/no/destination/set"',
            )
Пример #5
0
    def test_sync_info_file(self):
        """
        Test sync info is taken from mapping file.
        """
        mapping_file = os.path.join(os.path.dirname(os.path.dirname(__file__)),
                                    "src2dest_example.txt")

        cmd = "-M model -V vendor -f {}".format(mapping_file).split(" ")
        args = self.parser.parse_args(cmd)

        sources, destinations = cli.parse_sync_info(args)

        self.assertEqual(
            sources,
            ["/home/dm/Music/Rock", "/home/dm/Music/discographies/Band1"],
        )
        self.assertEqual(destinations,
                         ["Card/Music/Compilations/Rock", "Card/Music/Band1"])