예제 #1
0
def test_arg_parser__load__invalid_configuration():
    spec = SettingSpec(group=SettingType.CONFIGURATION,
                       flags=["-f"],
                       help="foo")
    arg_parser = ArgLoader(spec)
    with patch.object(sys, "argv", ["mnamer", "-f", "1"]):
        with pytest.raises(RuntimeError):
            arg_parser.load()
예제 #2
0
def test_arg_parser__load__valid_positional():
    spec = SettingSpec(group=SettingType.POSITIONAL,
                       flags=["f"],
                       help="foo",
                       type=int)
    arg_parser = ArgLoader(spec)
    with patch.object(sys, "argv", ["mnamer", "01"]):
        assert arg_parser.load() == {"f": 1}
예제 #3
0
def test_arg_parser__load__valid_directive():
    spec = SettingSpec(group=SettingType.DIRECTIVE,
                       flags=["-f"],
                       help="foo",
                       type=int)
    arg_parser = ArgLoader(spec)
    with patch.object(sys, "argv", ["mnamer", "-f", "01"]):
        assert arg_parser.load() == {"f": 1}
예제 #4
0
 def load(self):
     arg_loader = ArgLoader(*self.specifications())
     try:
         arguments = arg_loader.load()
     except RuntimeError as e:
         raise MnamerException(e)
     config_path = arguments.get("config_path", crawl_out(".mnamer-v2.json"))
     config = json_loads(str(config_path)) if config_path else {}
     if not self.config_ignore and not arguments.get("config_ignore"):
         self.bulk_apply(config)
     if arguments:
         self.bulk_apply(arguments)