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

Commitb7a6753

Browse files
committed
Use pathlib instead of low-level os module
1 parent2aed6b3 commitb7a6753

File tree

4 files changed

+50
-56
lines changed

4 files changed

+50
-56
lines changed

‎bpython/test/__init__.py‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
importunittest
22
importunittest.mock
33
importos
4+
frompathlibimportPath
45

56
frombpython.translationsimportinit
67

@@ -16,4 +17,4 @@ class MagicIterMock(unittest.mock.MagicMock):
1617
__next__=unittest.mock.Mock(return_value=None)
1718

1819

19-
TEST_CONFIG=os.path.join(os.path.dirname(__file__),"test.config")
20+
TEST_CONFIG=Path(__file__).parent/"test.config"

‎bpython/test/test_crashers.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ def processExited(self, reason):
9393
"-m",
9494
"bpython."+self.backend,
9595
"--config",
96-
TEST_CONFIG,
96+
str(TEST_CONFIG),
9797
),
9898
env=dict(TERM="vt100",LANG=os.environ.get("LANG","")),
9999
usePTY=(master,slave,os.ttyname(slave)),

‎bpython/test/test_importcompletion.py‎

Lines changed: 46 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -56,71 +56,65 @@ def test_from_package(self):
5656
classTestAvoidSymbolicLinks(unittest.TestCase):
5757
defsetUp(self):
5858
withtempfile.TemporaryDirectory()asimport_test_folder:
59-
os.mkdir(os.path.join(import_test_folder,"Level0"))
60-
os.mkdir(os.path.join(import_test_folder,"Right"))
61-
os.mkdir(os.path.join(import_test_folder,"Left"))
62-
63-
current_path=os.path.join(import_test_folder,"Level0")
64-
Path(os.path.join(current_path,"__init__.py")).touch()
65-
66-
current_path=os.path.join(current_path,"Level1")
67-
os.mkdir(current_path)
68-
Path(os.path.join(current_path,"__init__.py")).touch()
69-
70-
current_path=os.path.join(current_path,"Level2")
71-
os.mkdir(current_path)
72-
Path(os.path.join(current_path,"__init__.py")).touch()
73-
74-
os.symlink(
75-
os.path.join(import_test_folder,"Level0","Level1"),
76-
os.path.join(current_path,"Level3"),
77-
True,
59+
base_path=Path(import_test_folder)
60+
(base_path/"Level0"/"Level1"/"Level2").mkdir(parents=True)
61+
(base_path/"Left").mkdir(parents=True)
62+
(base_path/"Right").mkdir(parents=True)
63+
64+
current_path=base_path/"Level0"
65+
(current_path/"__init__.py").touch()
66+
67+
current_path=current_path/"Level1"
68+
(current_path/"__init__.py").touch()
69+
70+
current_path=current_path/"Level2"
71+
(current_path/"__init__.py").touch()
72+
# Level0/Level1/Level2/Level3 -> Level0/Level1
73+
(current_path/"Level3").symlink_to(
74+
base_path/"Level0"/"Level1",target_is_directory=True
7875
)
7976

80-
current_path=os.path.join(import_test_folder,"Right")
81-
Path(os.path.join(current_path,"__init__.py")).touch()
82-
83-
os.symlink(
84-
os.path.join(import_test_folder,"Left"),
85-
os.path.join(current_path,"toLeft"),
86-
True,
77+
current_path=base_path/"Right"
78+
(current_path/"__init__.py").touch()
79+
# Right/toLeft -> Left
80+
(current_path/"toLeft").symlink_to(
81+
base_path/"Left",target_is_directory=True
8782
)
8883

89-
current_path=os.path.join(import_test_folder,"Left")
90-
Path(os.path.join(current_path,"__init__.py")).touch()
91-
92-
os.symlink(
93-
os.path.join(import_test_folder,"Right"),
94-
os.path.join(current_path,"toRight"),
95-
True,
84+
current_path=base_path/"Left"
85+
(current_path/"__init__.py").touch()
86+
# Left/toRight -> Right
87+
(current_path/"toRight").symlink_to(
88+
base_path/"Right",target_is_directory=True
9689
)
9790

9891
self.module_gatherer=ModuleGatherer(
9992
[os.path.abspath(import_test_folder)]
10093
)
10194
whileself.module_gatherer.find_coroutine():
10295
pass
103-
self.filepaths= [
104-
"Left.toRight.toLeft",
105-
"Left.toRight",
106-
"Left",
107-
"Level0.Level1.Level2.Level3",
108-
"Level0.Level1.Level2",
109-
"Level0.Level1",
110-
"Level0",
111-
"Right",
112-
"Right.toLeft",
113-
"Right.toLeft.toRight",
114-
]
11596

11697
deftest_simple_symbolic_link_loop(self):
98+
filepaths= [
99+
"Left.toRight.toLeft",
100+
"Left.toRight",
101+
"Left",
102+
"Level0.Level1.Level2.Level3",
103+
"Level0.Level1.Level2",
104+
"Level0.Level1",
105+
"Level0",
106+
"Right",
107+
"Right.toLeft",
108+
"Right.toLeft.toRight",
109+
]
110+
117111
forthinginself.module_gatherer.modules:
118-
self.assertTrue(thinginself.filepaths)
112+
self.assertIn(thing,filepaths)
119113
ifthing=="Left.toRight.toLeft":
120-
self.filepaths.remove("Right.toLeft")
121-
self.filepaths.remove("Right.toLeft.toRight")
114+
filepaths.remove("Right.toLeft")
115+
filepaths.remove("Right.toLeft.toRight")
122116
ifthing=="Right.toLeft.toRight":
123-
self.filepaths.remove("Left.toRight.toLeft")
124-
self.filepaths.remove("Left.toRight")
125-
self.filepaths.remove(thing)
126-
self.assertFalse(self.filepaths)
117+
filepaths.remove("Left.toRight.toLeft")
118+
filepaths.remove("Left.toRight")
119+
filepaths.remove(thing)
120+
self.assertFalse(filepaths)

‎bpython/test/test_repl.py‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
importcollections
22
importinspect
3-
importos
43
importsocket
54
importsys
65
importtempfile
@@ -334,7 +333,7 @@ def test_create_config(self):
334333
config_path=Path(tmp_dir)/"newdir"/"config"
335334
self.repl.config.config_path=config_path
336335
self.repl.edit_config()
337-
self.assertTrue(os.path.exists(config_path))
336+
self.assertTrue(config_path.exists())
338337

339338

340339
classTestRepl(unittest.TestCase):

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2026 Movatter.jp