def test_plugin(self) -> None: activate_plugin("separate_libs") try: config = Config.default() config.add_imports = [ ImportStatement( "__future__", leafs=[ ImportLeaf("absolute_import"), ImportLeaf("print_function"), ImportLeaf("unicode_literals"), ], ) ] result = next( run_importanize_on_text( self.input_text.read_text(), self.input_text, config, RuntimeConfig(_config=config), )) assert result.organized == self.output_grouped_separate_libs.read_text( ) finally: deactivate_all_plugins()
def _test( self, stem: str, leafs: typing.List[ImportLeaf], expected: typing.List[str], sep: str = "\n", inline_comments: typing.List[str] = None, standalone_comments: typing.List[str] = None, ) -> None: """Facilitate the output tests of formatters""" statement = ImportStatement( stem, leafs=leafs, inline_comments=inline_comments, standalone_comments=standalone_comments, ) actual = self.formatter(statement, config=Config.default(), artifacts=Artifacts(sep=sep)).format() assert actual == sep.join(expected)
def test_bool(self) -> None: assert not Config.default() assert Config(path=Path("setup.py"))
def test_default(self) -> None: assert "*/.tox/*" in Config.default().exclude
def test_repr(self) -> None: assert repr(Config.default()) == Config.default().as_ini()
def test_str(self) -> None: assert str(Config.default()) == "<default pep8>" assert str(Config(path=Path("setup.py"))) == "setup.py"
def test_as_json(self) -> None: c = Config.default() assert json.loads(c.as_json()) == c.as_dict()
def test_as_dict(self) -> None: assert Config.default().as_dict()["formatter"] == "grouped" assert Config.default().as_dict()["groups"][0] == {"type": "stdlib"}
def test_merge(self) -> None: c = Config.default().merge(Config(length=100, formatter=LinesFormatter)) assert c.length == 100 assert c.formatter is LinesFormatter