@@ -56,71 +56,65 @@ def test_from_package(self):
5656class TestAvoidSymbolicLinks (unittest .TestCase ):
5757def setUp (self ):
5858with tempfile .TemporaryDirectory ()as import_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
9891self .module_gatherer = ModuleGatherer (
9992 [os .path .abspath (import_test_folder )]
10093 )
10194while self .module_gatherer .find_coroutine ():
10295pass
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
11697def test_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+
117111for thing in self .module_gatherer .modules :
118- self .assertTrue (thing in self . filepaths )
112+ self .assertIn (thing , filepaths )
119113if thing == "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" )
122116if thing == "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 )