Example #1
0
 def test_ini_invalid_add_imports(self) -> None:
     with pytest.raises(InvalidConfig):
         Config.from_ini(
             StdPath("invalid.ini"),
             "\n".join(
                 ["[importanize]", "add_imports=", "  from foo from bar"]),
         )
Example #2
0
 def test_ini(self) -> None:
     Config.from_ini(StdPath("config.ini"),
                     "\n".join(["[importanize]"
                                ])) == Config(StdPath("config.ini"))
     Config.from_ini(
         StdPath("config.ini"),
         "\n".join([
             "[importanize]",
             "after_imports_new_lines=5",
             "length=100",
             "formatter=lines",
             "groups=",
             "   stdlib",
             "   packages:mypackage",
             "exclude=exclude",
             "add_imports=",
             "   import foo",
             "allow_plugins=false",
         ]),
     ) == Config(
         path=StdPath("config.json"),
         after_imports_new_lines=5,
         length=100,
         formatter=LinesFormatter,
         groups=[
             GroupConfig(type="stdlib"),
             GroupConfig(type="packages", packages=["foo"]),
         ],
         exclude=["exclude"],
         add_imports=[ImportStatement("foo")],
         are_plugins_allowed=False,
     )
Example #3
0
 def test_ini_invalid_length(self) -> None:
     with pytest.raises(InvalidConfig):
         Config.from_ini(StdPath("invalid.ini"),
                         "\n".join(["[importanize]", "length=a"]))
     with pytest.raises(InvalidConfig):
         Config.from_ini(StdPath("invalid.ini"),
                         "\n".join(["[importanize]", "length=1"]))
Example #4
0
 def test_ini_invalid_new_lines(self) -> None:
     with pytest.raises(InvalidConfig):
         Config.from_ini(
             StdPath("invalid.ini"),
             "\n".join(["[importanize]", "after_imports_new_lines=a"]),
         )
     with pytest.raises(InvalidConfig):
         Config.from_ini(
             StdPath("invalid.ini"),
             "\n".join(["[importanize]", "after_imports_new_lines=10"]),
         )
Example #5
0
 def test_ini_invalid_formatter(self) -> None:
     with pytest.raises(InvalidConfig):
         Config.from_ini(
             StdPath("invalid.ini"),
             "\n".join(["[importanize]", "formatter=foo"]),
         )
Example #6
0
 def test_ini_invalid_require_packages(self) -> None:
     with pytest.raises(InvalidConfig):
         Config.from_ini(
             StdPath("invalid.ini"),
             "\n".join(["[importanize]", "groups=", "  packages"]),
         )
Example #7
0
 def test_ini_invalid_group_name(self) -> None:
     with pytest.raises(InvalidConfig):
         Config.from_ini(
             StdPath("invalid.ini"),
             "\n".join(["[importanize]", "groups=", "  foo"]),
         )
Example #8
0
 def test_ini_no_section(self) -> None:
     with pytest.raises(NoImportanizeConfig):
         Config.from_ini(StdPath("invalid.ini"), "")
Example #9
0
 def test_ini_invalid_plugins(self) -> None:
     with pytest.raises(InvalidConfig):
         Config.from_ini(
             StdPath("invalid.ini"),
             "\n".join(["[importanize]", "plugins=\n  foo"]),
         )