Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit196cfbe

Browse files
committed
Clean up test_util, reorganizing for readability
- Slightly improve import sorting, grouping, and formatting.- Move the cygpath pairs parameters into the test class, so they can be immediately above the tests that use them. This was almost the case in the past, but stopped being the case when helpers for some new tests above those were introduced (and those helpers can't be moved inside the class without extra complexity).- Rename TestIterableMember to _Member, so it is no longer named as a test class. The unittest framework wouldn't consider it one, since it doesn't derive from unittest.TestCase, but the pytest runner, which we're actually using, does. More importanly (since it has no test methods anyway), this makes clear to humans that it is a helper class for tests, rather than a class of tests.- Improve the style of _Member, and have its __repr__ show the actual class of the instance, so if future tests ever use a derived class of it--or if its name ever changes again--the type name in the repr will be correct.- Remove the setup method (of TestUtils). It looks like this may at one time have been intended as a setUp method (note the case difference), but it is unused and there doesn't seem to be any attempt to use the instance attribute it was setting.- Use R"" instead of r"" for raw strings representing Windows paths, so that some editors (at least VS Code) refrain from highlighting their contents as regular expressions.- Other very minor reformatting and slight comment rewording.
1 parent7dd5904 commit196cfbe

File tree

1 file changed

+46
-55
lines changed

1 file changed

+46
-55
lines changed

‎test/test_util.py

Lines changed: 46 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
# the BSD License: https://opensource.org/license/bsd-3-clause/
66

77
importcontextlib
8+
fromdatetimeimportdatetime
89
importos
910
importpathlib
1011
importpickle
@@ -13,7 +14,6 @@
1314
importtempfile
1415
importtime
1516
fromunittestimportSkipTest,mock,skipIf,skipUnless
16-
fromdatetimeimportdatetime
1717

1818
importddt
1919
importpytest
@@ -28,10 +28,6 @@
2828
utctz_to_altz,
2929
verify_utctz,
3030
)
31-
fromtest.libimport (
32-
TestBase,
33-
with_rw_repo,
34-
)
3531
fromgit.utilimport (
3632
Actor,
3733
BlockingLockFile,
@@ -43,41 +39,19 @@
4339
remove_password_if_present,
4440
rmtree,
4541
)
42+
fromtest.libimportTestBase,with_rw_repo
4643

4744

48-
_norm_cygpath_pairs= (
49-
(r"foo\bar","foo/bar"),
50-
(r"foo/bar","foo/bar"),
51-
(r"C:\Users","/cygdrive/c/Users"),
52-
(r"C:\d/e","/cygdrive/c/d/e"),
53-
("C:\\","/cygdrive/c/"),
54-
(r"\\server\C$\Users","//server/C$/Users"),
55-
(r"\\server\C$","//server/C$"),
56-
("\\\\server\\c$\\","//server/c$/"),
57-
(r"\\server\BAR/","//server/BAR/"),
58-
(r"D:/Apps","/cygdrive/d/Apps"),
59-
(r"D:/Apps\fOO","/cygdrive/d/Apps/fOO"),
60-
(r"D:\Apps/123","/cygdrive/d/Apps/123"),
61-
)
62-
63-
_unc_cygpath_pairs= (
64-
(r"\\?\a:\com","/cygdrive/a/com"),
65-
(r"\\?\a:/com","/cygdrive/a/com"),
66-
(r"\\?\UNC\server\D$\Apps","//server/D$/Apps"),
67-
)
68-
69-
70-
classTestIterableMember(object):
71-
72-
"""A member of an iterable list"""
45+
class_Member:
46+
"""A member of an IterableList."""
7347

74-
__slots__="name"
48+
__slots__=("name",)
7549

7650
def__init__(self,name):
7751
self.name=name
7852

7953
def__repr__(self):
80-
return"TestIterableMember(%r)"%self.name
54+
returnf"{type(self).__name__}({self.name!r})"
8155

8256

8357
@contextlib.contextmanager
@@ -106,13 +80,6 @@ def _tmpdir_for_file_not_found():
10680

10781
@ddt.ddt
10882
classTestUtils(TestBase):
109-
defsetup(self):
110-
self.testdict= {
111-
"string":"42",
112-
"int":42,
113-
"array": [42],
114-
}
115-
11683
deftest_rmtree_deletes_nested_dir_with_files(self):
11784
withtempfile.TemporaryDirectory()asparent:
11885
td=pathlib.Path(parent,"testdir")
@@ -131,7 +98,7 @@ def test_rmtree_deletes_nested_dir_with_files(self):
13198
@skipIf(sys.platform=="cygwin","Cygwin can't set the permissions that make the test meaningful.")
13299
deftest_rmtree_deletes_dir_with_readonly_files(self):
133100
# Automatically works on Unix, but requires special handling on Windows.
134-
# Not to be confused with _tmpdir_to_force_permission_error(which is used below).
101+
# Not to be confused withwhat_tmpdir_to_force_permission_errorsets up (see below).
135102
withtempfile.TemporaryDirectory()asparent:
136103
td=pathlib.Path(parent,"testdir")
137104
fordintd,td/"sub":
@@ -179,6 +146,27 @@ def test_rmtree_does_not_wrap_unless_called_for(self, case):
179146
exceptSkipTestasex:
180147
self.fail(f"rmtree unexpectedly attempts skip:{ex!r}")
181148

149+
_norm_cygpath_pairs= (
150+
(R"foo\bar","foo/bar"),
151+
(R"foo/bar","foo/bar"),
152+
(R"C:\Users","/cygdrive/c/Users"),
153+
(R"C:\d/e","/cygdrive/c/d/e"),
154+
("C:\\","/cygdrive/c/"),
155+
(R"\\server\C$\Users","//server/C$/Users"),
156+
(R"\\server\C$","//server/C$"),
157+
("\\\\server\\c$\\","//server/c$/"),
158+
(R"\\server\BAR/","//server/BAR/"),
159+
(R"D:/Apps","/cygdrive/d/Apps"),
160+
(R"D:/Apps\fOO","/cygdrive/d/Apps/fOO"),
161+
(R"D:\Apps/123","/cygdrive/d/Apps/123"),
162+
)
163+
164+
_unc_cygpath_pairs= (
165+
(R"\\?\a:\com","/cygdrive/a/com"),
166+
(R"\\?\a:/com","/cygdrive/a/com"),
167+
(R"\\?\UNC\server\D$\Apps","//server/D$/Apps"),
168+
)
169+
182170
# FIXME: Mark only the /proc-prefixing cases xfail, somehow (or fix them).
183171
@pytest.mark.xfail(
184172
reason="Many return paths prefixed /proc/cygdrive instead.",
@@ -192,16 +180,16 @@ def test_cygpath_ok(self, case):
192180
self.assertEqual(cwpath,cpath,wpath)
193181

194182
@pytest.mark.xfail(
195-
reason=r'2nd example r".\bar" -> "bar" fails, returns "./bar"',
183+
reason=R'2nd example r".\bar" -> "bar" fails, returns "./bar"',
196184
raises=AssertionError,
197185
)
198186
@skipUnless(sys.platform=="cygwin","Paths specifically for Cygwin.")
199187
@ddt.data(
200-
(r"./bar","bar"),
201-
(r".\bar","bar"),# FIXME: Mark only this one xfail, somehow (or fix it).
202-
(r"../bar","../bar"),
203-
(r"..\bar","../bar"),
204-
(r"../bar/.\foo/../chu","../bar/chu"),
188+
(R"./bar","bar"),
189+
(R".\bar","bar"),# FIXME: Mark only this one xfail, somehow (or fix it).
190+
(R"../bar","../bar"),
191+
(R"..\bar","../bar"),
192+
(R"../bar/.\foo/../chu","../bar/chu"),
205193
)
206194
deftest_cygpath_norm_ok(self,case):
207195
wpath,cpath=case
@@ -210,12 +198,12 @@ def test_cygpath_norm_ok(self, case):
210198

211199
@skipUnless(sys.platform=="cygwin","Paths specifically for Cygwin.")
212200
@ddt.data(
213-
r"C:",
214-
r"C:Relative",
215-
r"D:Apps\123",
216-
r"D:Apps/123",
217-
r"\\?\a:rel",
218-
r"\\share\a:rel",
201+
R"C:",
202+
R"C:Relative",
203+
R"D:Apps\123",
204+
R"D:Apps/123",
205+
R"\\?\a:rel",
206+
R"\\share\a:rel",
219207
)
220208
deftest_cygpath_invalids(self,wpath):
221209
cwpath=cygpath(wpath)
@@ -380,15 +368,18 @@ def test_actor_from_string(self):
380368
Actor("name last another","some-very-long-email@example.com"),
381369
)
382370

383-
@ddt.data(("name",""), ("name","prefix_"))
371+
@ddt.data(
372+
("name",""),
373+
("name","prefix_"),
374+
)
384375
deftest_iterable_list(self,case):
385376
name,prefix=case
386377
ilist=IterableList(name,prefix)
387378

388379
name1="one"
389380
name2="two"
390-
m1=TestIterableMember(prefix+name1)
391-
m2=TestIterableMember(prefix+name2)
381+
m1=_Member(prefix+name1)
382+
m2=_Member(prefix+name2)
392383

393384
ilist.extend((m1,m2))
394385

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp