mirror of
https://github.com/arsenetar/dupeguru.git
synced 2024-10-31 22:05:58 +00:00
Code cleanups in hscommon\tests
This commit is contained in:
parent
0189c29f47
commit
f9316de244
@ -19,7 +19,7 @@ from ..path import Path
|
|||||||
from ..testutil import eq_
|
from ..testutil import eq_
|
||||||
|
|
||||||
|
|
||||||
class TestCase_GetConflictedName:
|
class TestCaseGetConflictedName:
|
||||||
def test_simple(self):
|
def test_simple(self):
|
||||||
name = get_conflicted_name(["bar"], "bar")
|
name = get_conflicted_name(["bar"], "bar")
|
||||||
eq_("[000] bar", name)
|
eq_("[000] bar", name)
|
||||||
@ -46,7 +46,7 @@ class TestCase_GetConflictedName:
|
|||||||
eq_("[000] bar", name)
|
eq_("[000] bar", name)
|
||||||
|
|
||||||
|
|
||||||
class TestCase_GetUnconflictedName:
|
class TestCaseGetUnconflictedName:
|
||||||
def test_main(self):
|
def test_main(self):
|
||||||
eq_("foobar", get_unconflicted_name("[000] foobar"))
|
eq_("foobar", get_unconflicted_name("[000] foobar"))
|
||||||
eq_("foobar", get_unconflicted_name("[9999] 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"))
|
eq_("foo [000] bar", get_unconflicted_name("foo [000] bar"))
|
||||||
|
|
||||||
|
|
||||||
class TestCase_IsConflicted:
|
class TestCaseIsConflicted:
|
||||||
def test_main(self):
|
def test_main(self):
|
||||||
assert is_conflicted("[000] foobar")
|
assert is_conflicted("[000] foobar")
|
||||||
assert is_conflicted("[9999] foobar")
|
assert is_conflicted("[9999] foobar")
|
||||||
@ -66,7 +66,7 @@ class TestCase_IsConflicted:
|
|||||||
assert not is_conflicted("foo [000] bar")
|
assert not is_conflicted("foo [000] bar")
|
||||||
|
|
||||||
|
|
||||||
class TestCase_move_copy:
|
class TestCaseMoveCopy:
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def do_setup(self, request):
|
def do_setup(self, request):
|
||||||
tmpdir = request.getfixturevalue("tmpdir")
|
tmpdir = request.getfixturevalue("tmpdir")
|
||||||
|
@ -51,7 +51,7 @@ def test_init_with_tuple_and_list(force_ossep):
|
|||||||
|
|
||||||
def test_init_with_invalid_value(force_ossep):
|
def test_init_with_invalid_value(force_ossep):
|
||||||
try:
|
try:
|
||||||
path = Path(42) # noqa: F841
|
Path(42)
|
||||||
assert False
|
assert False
|
||||||
except TypeError:
|
except TypeError:
|
||||||
pass
|
pass
|
||||||
@ -142,8 +142,6 @@ def test_path_slice(force_ossep):
|
|||||||
eq_((), foobar[:foobar])
|
eq_((), foobar[:foobar])
|
||||||
abcd = Path("a/b/c/d")
|
abcd = Path("a/b/c/d")
|
||||||
a = Path("a")
|
a = Path("a")
|
||||||
b = Path("b") # noqa: #F841
|
|
||||||
c = Path("c") # noqa: #F841
|
|
||||||
d = Path("d")
|
d = Path("d")
|
||||||
z = Path("z")
|
z = Path("z")
|
||||||
eq_("b/c", abcd[a:d])
|
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())
|
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.
|
# if Path() is called with a path as value, just return value.
|
||||||
p = Path("foo/bar")
|
p = Path("foo/bar")
|
||||||
assert Path(p) is p
|
assert Path(p) is p
|
||||||
|
@ -91,7 +91,7 @@ def test_make_sure_theres_no_messup_between_queries():
|
|||||||
threads = []
|
threads = []
|
||||||
for i in range(1, 101):
|
for i in range(1, 101):
|
||||||
t = threading.Thread(target=run, args=(i,))
|
t = threading.Thread(target=run, args=(i,))
|
||||||
t.start
|
t.start()
|
||||||
threads.append(t)
|
threads.append(t)
|
||||||
while threads:
|
while threads:
|
||||||
time.sleep(0.1)
|
time.sleep(0.1)
|
||||||
|
@ -19,6 +19,7 @@ class TestRow(Row):
|
|||||||
self._index = index
|
self._index = index
|
||||||
|
|
||||||
def load(self):
|
def load(self):
|
||||||
|
# Does nothing for test
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def save(self):
|
def save(self):
|
||||||
@ -75,14 +76,17 @@ def test_allow_edit_when_attr_is_property_with_fset():
|
|||||||
class TestRow(Row):
|
class TestRow(Row):
|
||||||
@property
|
@property
|
||||||
def foo(self):
|
def foo(self):
|
||||||
|
# property only for existence checks
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def bar(self):
|
def bar(self):
|
||||||
|
# property only for existence checks
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@bar.setter
|
@bar.setter
|
||||||
def bar(self, value):
|
def bar(self, value):
|
||||||
|
# setter only for existence checks
|
||||||
pass
|
pass
|
||||||
|
|
||||||
row = TestRow(Table())
|
row = TestRow(Table())
|
||||||
@ -97,10 +101,12 @@ def test_can_edit_prop_has_priority_over_fset_checks():
|
|||||||
class TestRow(Row):
|
class TestRow(Row):
|
||||||
@property
|
@property
|
||||||
def bar(self):
|
def bar(self):
|
||||||
|
# property only for existence checks
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@bar.setter
|
@bar.setter
|
||||||
def bar(self, value):
|
def bar(self, value):
|
||||||
|
# setter only for existence checks
|
||||||
pass
|
pass
|
||||||
|
|
||||||
can_edit_bar = False
|
can_edit_bar = False
|
||||||
|
@ -236,49 +236,8 @@ def test_multi_replace():
|
|||||||
|
|
||||||
# --- Files
|
# --- 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:
|
class TestCaseDeleteIfEmpty:
|
||||||
# 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:
|
|
||||||
def test_is_empty(self, tmpdir):
|
def test_is_empty(self, tmpdir):
|
||||||
testpath = Path(str(tmpdir))
|
testpath = Path(str(tmpdir))
|
||||||
assert delete_if_empty(testpath)
|
assert delete_if_empty(testpath)
|
||||||
@ -330,7 +289,7 @@ class TestCase_delete_if_empty:
|
|||||||
delete_if_empty(Path(str(tmpdir))) # no crash
|
delete_if_empty(Path(str(tmpdir))) # no crash
|
||||||
|
|
||||||
|
|
||||||
class TestCase_open_if_filename:
|
class TestCaseOpenIfFilename:
|
||||||
def test_file_name(self, tmpdir):
|
def test_file_name(self, tmpdir):
|
||||||
filepath = str(tmpdir.join("test.txt"))
|
filepath = str(tmpdir.join("test.txt"))
|
||||||
open(filepath, "wb").write(b"test_data")
|
open(filepath, "wb").write(b"test_data")
|
||||||
@ -355,7 +314,7 @@ class TestCase_open_if_filename:
|
|||||||
file.close()
|
file.close()
|
||||||
|
|
||||||
|
|
||||||
class TestCase_FileOrPath:
|
class TestCaseFileOrPath:
|
||||||
def test_path(self, tmpdir):
|
def test_path(self, tmpdir):
|
||||||
filepath = str(tmpdir.join("test.txt"))
|
filepath = str(tmpdir.join("test.txt"))
|
||||||
open(filepath, "wb").write(b"test_data")
|
open(filepath, "wb").write(b"test_data")
|
||||||
|
Loading…
Reference in New Issue
Block a user