Пример #1
0
def create_row_generator(args: argparse.Namespace) -> RowGenerator:
    """ Generates a row generator according to the given CLI arguments. """
    if "comp" in args and args.comp is not None and "start_row" in args and args.start_row is not None:
        sys.exit("You may not specify a custom start row with a composition")
    elif "comp" in args and args.comp is not None:
        try:
            return ComplibCompositionGenerator.from_arg(args.comp)
        except (PrivateCompError, InvalidCompError) as e:
            sys.exit(f"Bad value for '--comp': {e}")
    elif "method" in args and args.method is not None:
        try:
            return generator_from_special_title(args.method, args.start_row) or \
                MethodPlaceNotationGenerator(
                    args.method,
                    parse_call(args.bob),
                    parse_call(args.single),
                    args.start_row,
                    args.start_index
                )
        except MethodNotFoundError as e:
            sys.exit(f"Bad value for '--method': {e}")
    elif "place_notation" in args and args.place_notation is not None:
        try:
            stage, place_notation = parse_place_notation(args.place_notation)
            return PlaceNotationGenerator(stage, place_notation,
                                          parse_call(args.bob),
                                          parse_call(args.single),
                                          args.start_index)
        except PlaceNotationError as e:
            sys.exit(f"Bad value for '--place-notation': {e}")

    raise AssertionError(
        "One of --method, --comp or --place-notation should always be defined")
Пример #2
0
def create_row_generator(args: argparse.Namespace) -> RowGenerator:
    """ Generates a row generator according to the given CLI arguments. """
    if "comp_url" in args and args.comp_url is not None:
        try:
            row_gen = ComplibCompositionGenerator.from_url(args.comp_url)
        except (PrivateCompError, InvalidCompError) as e:
            sys.exit(f"Bad value for '--comp': {e}")
    elif "comp" in args and args.comp is not None:
        try:
            row_gen = ComplibCompositionGenerator(args.comp)
        except (PrivateCompError, InvalidCompError) as e:
            sys.exit(f"Bad value for '--comp': {e}")
    elif "method" in args:
        try:
            row_gen = generator_from_special_title(args.method) or \
                      MethodPlaceNotationGenerator(
                          args.method,
                          parse_call(args.bob),
                          parse_call(args.single),
                          args.start_index
                      )
        except MethodNotFoundError as e:
            sys.exit(f"Bad value for '--method': {e}")
    else:
        assert False, \
            "This shouldn't be possible because one of --method and --comp should always be defined"

    return row_gen
Пример #3
0
    def test_call_parsing_errors(self):
        test_cases = [("xx:14", "Location 'xx' is not an integer."),
                      ("", "Place notation strings cannot be empty."),
                      ("  /  /    ", "Place notation strings cannot be empty."),
                      ("14/ 1234  ", "Location 0 has two conflicting calls: '14' and '1234'."),
                      (":::  /", "Call specification ':::' should contain at most one ':'.")]

        for (input_arg, expected_message) in test_cases:
            with self.subTest(input=input_arg, expected_message=expected_message):
                with self.assertRaises(CallParseError) as e:
                    parse_call(input_arg)
                self.assertEqual(expected_message, e.exception.message)
Пример #4
0
    def test_call_parsing(self):
        test_cases = [
            ("14", {
                0: "14"
            }),
            ("3.123", {
                0: "3.123"
            }),
            ("  0 \t:  \n 16   ", {
                0: "16"
            }),
            ("20: 70", {
                20: "70"
            }),
            ("20: 70/ 14", {
                20: "70",
                0: "14"
            }),
        ]

        for (input_arg, expected_call_dict) in test_cases:
            with self.subTest(input=input_arg,
                              expected_call_dict=expected_call_dict):
                self.assertEqual(CallDef(expected_call_dict),
                                 parse_call(input_arg))