Exemplo n.º 1
0
    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()
Exemplo n.º 2
0
 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)
Exemplo n.º 3
0
 def test_bool(self) -> None:
     assert not Config.default()
     assert Config(path=Path("setup.py"))
Exemplo n.º 4
0
 def test_default(self) -> None:
     assert "*/.tox/*" in Config.default().exclude
Exemplo n.º 5
0
 def test_repr(self) -> None:
     assert repr(Config.default()) == Config.default().as_ini()
Exemplo n.º 6
0
 def test_str(self) -> None:
     assert str(Config.default()) == "<default pep8>"
     assert str(Config(path=Path("setup.py"))) == "setup.py"
Exemplo n.º 7
0
 def test_as_json(self) -> None:
     c = Config.default()
     assert json.loads(c.as_json()) == c.as_dict()
Exemplo n.º 8
0
 def test_as_dict(self) -> None:
     assert Config.default().as_dict()["formatter"] == "grouped"
     assert Config.default().as_dict()["groups"][0] == {"type": "stdlib"}
Exemplo n.º 9
0
 def test_merge(self) -> None:
     c = Config.default().merge(Config(length=100,
                                       formatter=LinesFormatter))
     assert c.length == 100
     assert c.formatter is LinesFormatter