Exemplo n.º 1
0
    def test_file(self) -> None:
        p = StdPath("test").with_streams(
            filein=OpenBytesIO(b"hello world"), fileout=OpenBytesIO()
        )

        assert p.read_text() == "hello world"

        p.write_text("hello mars")

        assert p.fileout.read() == b"hello mars"
Exemplo n.º 2
0
 def test_aggregator_invalid(self) -> None:
     stdin = OpenBytesIO((TEST_DATA / "invalid.py").read_bytes())
     stdout = OpenBytesIO()
     result = Aggregator(
         RuntimeConfig(
             _config=CONFIG,
             _paths=[StdPath("-").with_streams(stdin=stdin, stdout=stdout)],
             show_header=True,
         ))()
     assert result == 1
     assert stdout.read().decode("utf-8") == ""
Exemplo n.º 3
0
 def test_invalid_config(self) -> None:
     stdin = OpenBytesIO((TEST_DATA / "output_grouped.py").read_bytes())
     stdout = OpenBytesIO()
     result = Aggregator(
         RuntimeConfig(
             config_path=__file__,
             _paths=[StdPath("-").with_streams(stdin=stdin, stdout=stdout)],
             show_header=True,
         ))()
     assert result == 1
     assert stdout.read().decode("utf-8") == ""
Exemplo n.º 4
0
 def test_aggregator_no_changes(self) -> None:
     stdin = OpenBytesIO((TEST_DATA / "output_grouped.py").read_bytes())
     stdout = OpenBytesIO()
     result = Aggregator(
         RuntimeConfig(
             _config=CONFIG,
             _paths=[StdPath("-").with_streams(stdin=stdin, stdout=stdout)],
             show_header=True,
             is_subconfig_allowed=False,
         ))()
     assert result == 0
     assert stdout.read().decode("utf-8") == ""
Exemplo n.º 5
0
 def test_aggregator_subconfig(self) -> None:
     stdout = OpenBytesIO()
     result = Aggregator(
         RuntimeConfig(
             _config=CONFIG,
             _paths=[
                 StdPath(
                     TEST_DATA / "subconfig" /
                     "input_few_imports.py").with_streams(fileout=stdout)
             ],
             show_header=True,
         ))()
     assert result == 0
     assert (TEST_DATA / "subconfig" / "output_grouped_few_imports.py"
             ).read_text() in stdout.read().decode("utf-8")
Exemplo n.º 6
0
 def test_print_aggregator_piped(self) -> None:
     stdin = OpenBytesIO((TEST_DATA / "input.py").read_bytes())
     stdout = OpenBytesIO()
     out = OpenStringIO()
     result = PrintAggregator(
         RuntimeConfig(
             _config=CONFIG,
             _paths=[StdPath("-").with_streams(stdin=stdin, stdout=stdout)],
             show_header=True,
             stdout=out,
             is_subconfig_allowed=False,
         ))()
     assert result == 0
     assert str(TEST_DATA / "input.py") not in out.read()
     assert (
         TEST_DATA /
         "output_grouped.py").read_text() in stdout.read().decode("utf-8")
Exemplo n.º 7
0
def test_open_bytes_io() -> None:
    fid = OpenBytesIO(b"hello")
    assert fid.read() == b"hello"
    assert fid.read() == b"hello"
    fid.close()
    assert fid.read() == b"hello"