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"]), )
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, )
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"]))
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"]), )
def test_ini_invalid_formatter(self) -> None: with pytest.raises(InvalidConfig): Config.from_ini( StdPath("invalid.ini"), "\n".join(["[importanize]", "formatter=foo"]), )
def test_ini_invalid_require_packages(self) -> None: with pytest.raises(InvalidConfig): Config.from_ini( StdPath("invalid.ini"), "\n".join(["[importanize]", "groups=", " packages"]), )
def test_ini_invalid_group_name(self) -> None: with pytest.raises(InvalidConfig): Config.from_ini( StdPath("invalid.ini"), "\n".join(["[importanize]", "groups=", " foo"]), )
def test_ini_no_section(self) -> None: with pytest.raises(NoImportanizeConfig): Config.from_ini(StdPath("invalid.ini"), "")
def test_ini_invalid_plugins(self) -> None: with pytest.raises(InvalidConfig): Config.from_ini( StdPath("invalid.ini"), "\n".join(["[importanize]", "plugins=\n foo"]), )