From f9316de244aef5b6105e8474bb3c92b46208dd55 Mon Sep 17 00:00:00 2001 From: Andrew Senetar Date: Sat, 21 Aug 2021 16:25:33 -0500 Subject: [PATCH] Code cleanups in hscommon\tests --- hscommon/tests/conflict_test.py | 8 +++--- hscommon/tests/path_test.py | 6 ++--- hscommon/tests/sqlite_test.py | 2 +- hscommon/tests/table_test.py | 6 +++++ hscommon/tests/util_test.py | 47 +++------------------------------ 5 files changed, 16 insertions(+), 53 deletions(-) diff --git a/hscommon/tests/conflict_test.py b/hscommon/tests/conflict_test.py index 1ad444df..20fd90a2 100644 --- a/hscommon/tests/conflict_test.py +++ b/hscommon/tests/conflict_test.py @@ -19,7 +19,7 @@ from ..path import Path from ..testutil import eq_ -class TestCase_GetConflictedName: +class TestCaseGetConflictedName: def test_simple(self): name = get_conflicted_name(["bar"], "bar") eq_("[000] bar", name) @@ -46,7 +46,7 @@ class TestCase_GetConflictedName: eq_("[000] bar", name) -class TestCase_GetUnconflictedName: +class TestCaseGetUnconflictedName: def test_main(self): eq_("foobar", get_unconflicted_name("[000] foobar")) eq_("foobar", get_unconflicted_name("[9999] foobar")) @@ -56,7 +56,7 @@ class TestCase_GetUnconflictedName: eq_("foo [000] bar", get_unconflicted_name("foo [000] bar")) -class TestCase_IsConflicted: +class TestCaseIsConflicted: def test_main(self): assert is_conflicted("[000] foobar") assert is_conflicted("[9999] foobar") @@ -66,7 +66,7 @@ class TestCase_IsConflicted: assert not is_conflicted("foo [000] bar") -class TestCase_move_copy: +class TestCaseMoveCopy: @pytest.fixture def do_setup(self, request): tmpdir = request.getfixturevalue("tmpdir") diff --git a/hscommon/tests/path_test.py b/hscommon/tests/path_test.py index 35e64656..806b85c5 100644 --- a/hscommon/tests/path_test.py +++ b/hscommon/tests/path_test.py @@ -51,7 +51,7 @@ def test_init_with_tuple_and_list(force_ossep): def test_init_with_invalid_value(force_ossep): try: - path = Path(42) # noqa: F841 + Path(42) assert False except TypeError: pass @@ -142,8 +142,6 @@ def test_path_slice(force_ossep): eq_((), foobar[:foobar]) abcd = Path("a/b/c/d") a = Path("a") - b = Path("b") # noqa: #F841 - c = Path("c") # noqa: #F841 d = Path("d") z = Path("z") eq_("b/c", abcd[a:d]) @@ -216,7 +214,7 @@ def test_str_repr_of_mix_between_non_ascii_str_and_unicode(force_ossep): eq_("foo\u00e9/bar".encode(sys.getfilesystemencoding()), p.tobytes()) -def test_Path_of_a_Path_returns_self(force_ossep): +def test_path_of_a_path_returns_self(force_ossep): # if Path() is called with a path as value, just return value. p = Path("foo/bar") assert Path(p) is p diff --git a/hscommon/tests/sqlite_test.py b/hscommon/tests/sqlite_test.py index 4d7aa0a9..943bfefd 100644 --- a/hscommon/tests/sqlite_test.py +++ b/hscommon/tests/sqlite_test.py @@ -91,7 +91,7 @@ def test_make_sure_theres_no_messup_between_queries(): threads = [] for i in range(1, 101): t = threading.Thread(target=run, args=(i,)) - t.start + t.start() threads.append(t) while threads: time.sleep(0.1) diff --git a/hscommon/tests/table_test.py b/hscommon/tests/table_test.py index 468675b4..0a33adce 100644 --- a/hscommon/tests/table_test.py +++ b/hscommon/tests/table_test.py @@ -19,6 +19,7 @@ class TestRow(Row): self._index = index def load(self): + # Does nothing for test pass def save(self): @@ -75,14 +76,17 @@ def test_allow_edit_when_attr_is_property_with_fset(): class TestRow(Row): @property def foo(self): + # property only for existence checks pass @property def bar(self): + # property only for existence checks pass @bar.setter def bar(self, value): + # setter only for existence checks pass row = TestRow(Table()) @@ -97,10 +101,12 @@ def test_can_edit_prop_has_priority_over_fset_checks(): class TestRow(Row): @property def bar(self): + # property only for existence checks pass @bar.setter def bar(self, value): + # setter only for existence checks pass can_edit_bar = False diff --git a/hscommon/tests/util_test.py b/hscommon/tests/util_test.py index b3d6c4ec..fbf0775c 100644 --- a/hscommon/tests/util_test.py +++ b/hscommon/tests/util_test.py @@ -236,49 +236,8 @@ def test_multi_replace(): # --- Files -# These test cases needed https://github.com/hsoft/pytest-monkeyplus/ which appears to not be compatible with latest -# pytest, looking at where this is used only appears to be in hscommon.localize_all_stringfiles at top level. -# Right now this repo does not seem to utilize any of that functionality so going to leave these tests out for now. -# TODO decide if fixing these tests is worth it or not. -# class TestCase_modified_after: -# def test_first_is_modified_after(self, monkeyplus): -# monkeyplus.patch_osstat("first", st_mtime=42) -# monkeyplus.patch_osstat("second", st_mtime=41) -# assert modified_after("first", "second") - -# def test_second_is_modified_after(self, monkeyplus): -# monkeyplus.patch_osstat("first", st_mtime=42) -# monkeyplus.patch_osstat("second", st_mtime=43) -# assert not modified_after("first", "second") - -# def test_same_mtime(self, monkeyplus): -# monkeyplus.patch_osstat("first", st_mtime=42) -# monkeyplus.patch_osstat("second", st_mtime=42) -# assert not modified_after("first", "second") - -# def test_first_file_does_not_exist(self, monkeyplus): -# # when the first file doesn't exist, we return False -# monkeyplus.patch_osstat("second", st_mtime=42) -# assert not modified_after("does_not_exist", "second") # no crash - -# def test_second_file_does_not_exist(self, monkeyplus): -# # when the second file doesn't exist, we return True -# monkeyplus.patch_osstat("first", st_mtime=42) -# assert modified_after("first", "does_not_exist") # no crash - -# def test_first_file_is_none(self, monkeyplus): -# # when the first file is None, we return False -# monkeyplus.patch_osstat("second", st_mtime=42) -# assert not modified_after(None, "second") # no crash - -# def test_second_file_is_none(self, monkeyplus): -# # when the second file is None, we return True -# monkeyplus.patch_osstat("first", st_mtime=42) -# assert modified_after("first", None) # no crash - - -class TestCase_delete_if_empty: +class TestCaseDeleteIfEmpty: def test_is_empty(self, tmpdir): testpath = Path(str(tmpdir)) assert delete_if_empty(testpath) @@ -330,7 +289,7 @@ class TestCase_delete_if_empty: delete_if_empty(Path(str(tmpdir))) # no crash -class TestCase_open_if_filename: +class TestCaseOpenIfFilename: def test_file_name(self, tmpdir): filepath = str(tmpdir.join("test.txt")) open(filepath, "wb").write(b"test_data") @@ -355,7 +314,7 @@ class TestCase_open_if_filename: file.close() -class TestCase_FileOrPath: +class TestCaseFileOrPath: def test_path(self, tmpdir): filepath = str(tmpdir.join("test.txt")) open(filepath, "wb").write(b"test_data")