From b653d925d159f41430591e394283e84c1e911495 Mon Sep 17 00:00:00 2001 From: Dilawar Singh <dilawar@subcom.tech> Date: Tue, 11 Oct 2022 09:59:29 +0530 Subject: [PATCH] fix: Typos and tests fixes Create a temp directory and save test data there. --- tests/test_cli.py | 12 ------------ tests/test_methods.py | 42 +++++++++++++++++++++--------------------- tests/test_sanity.py | 2 +- 3 files changed, 22 insertions(+), 34 deletions(-) delete mode 100644 tests/test_cli.py diff --git a/tests/test_cli.py b/tests/test_cli.py deleted file mode 100644 index d12e887..0000000 --- a/tests/test_cli.py +++ /dev/null @@ -1,12 +0,0 @@ -from bitia.__main__ import run_user_input - - -def test_cli_sanity(): - lines = [] - for line in run_user_input("ls -ltr /", output_lines=lines): - print(11, line) - assert len(lines) > 10, "Too few lines" - - -if __name__ == "__main__": - test_cli_sanity() diff --git a/tests/test_methods.py b/tests/test_methods.py index eb2645d..5a91390 100644 --- a/tests/test_methods.py +++ b/tests/test_methods.py @@ -11,24 +11,24 @@ _common_hashes = { def test_filehash(): - tempdir = tempfile.gettempdir() - f1 = Path(tempdir) / "a.txt" - f2 = Path(tempdir) / "b.txt" - - for _c, _h in _common_hashes.items(): - f1.write_text(_c) - assert f1.read_text() == _c - print(f"Computing hash of {f1}, content: {_c}") - assert sha256sum(f1) == _h - - t1 = "ls -ltrh /" - f1.write_text(t1) - f2.write_text(t1) - assert sha256sum(f1) == sha256sum(f2) - - t2 = "ls -ltrh" - f2.write_text(t2) - assert sha256sum(f1) != sha256sum(f2) - - f1.write_text(t2) - assert sha256sum(f1) == sha256sum(f2) + with tempfile.TemporaryDirectory() as tempdir: + f1 = Path(tempdir) / "a.txt" + f2 = Path(tempdir) / "b.txt" + + for _c, _h in _common_hashes.items(): + f1.write_text(_c) + assert f1.read_text() == _c + print(f"Computing hash of {f1}, content: {_c}") + assert sha256sum(f1) == _h + + t1 = "ls -ltrh /" + f1.write_text(t1) + f2.write_text(t1) + assert sha256sum(f1) == sha256sum(f2) + + t2 = "ls -ltrh" + f2.write_text(t2) + assert sha256sum(f1) != sha256sum(f2) + + f1.write_text(t2) + assert sha256sum(f1) == sha256sum(f2) diff --git a/tests/test_sanity.py b/tests/test_sanity.py index 4da329c..b2cf6b1 100644 --- a/tests/test_sanity.py +++ b/tests/test_sanity.py @@ -18,4 +18,4 @@ def test_run_simple(capsys): bitia.__main__.run_user_input("ls -ltr /", rerun=True) captured = capsys.readouterr() l2 = captured.out - assert SequenceMatcher(a=l1, b=l2).ratio() > 0.plain9 + assert SequenceMatcher(a=l1, b=l2).ratio() > 0.9 -- GitLab