Beispiel #1
0
 def test_json(self) -> None:
     assert Config.from_json(StdPath("config.json"),
                             "{}") == Config(StdPath("config.json"))
     assert Config.from_json(
         StdPath("config.json"),
         json.dumps({
             "after_imports_new_lines": "5",
             "length": "100",
             "formatter": "lines",
             "groups": [{
                 "type": "remainder"
             }],
             "exclude": ["exclude"],
             "add_imports": ["import foo"],
         }),
     ) == Config(
         path=StdPath("config.json"),
         after_imports_new_lines=5,
         length=100,
         formatter=LinesFormatter,
         groups=[GroupConfig(type="remainder")],
         exclude=["exclude"],
         add_imports=(ImportStatement("foo"), ),
     )
Beispiel #2
0
 def test_json_invalid_json(self) -> None:
     with pytest.raises(NoImportanizeConfig):
         Config.from_json(StdPath("invalid.json"), "invalid data")
     with pytest.raises(InvalidConfig):
         Config.from_json(StdPath("invalid.json"), "{'length': 'a'}")