@@ -1022,137 +1022,70 @@ def test_realpath_mode(self):
10221022 os .symlink ("dir" , ABSTFN + "\\ link2" )
10231023 os .symlink ("nonexistent" , ABSTFN + "\\ broken" )
10241024 os .symlink ("cycle" , ABSTFN + "\\ cycle" )
1025- def check (path , mode , expected , errno = None ):
1025+ def check (path , modes , expected , errno = None ):
10261026 path = path .replace ('/' , '\\ ' )
10271027 if isinstance (expected , str ):
10281028 assert errno is None
1029- self .assertEqual (realpath (path , strict = mode ),
1030- ABSTFN + expected .replace ('/' , '\\ ' ))
1029+ expected = expected .replace ('/' , os .sep )
1030+ for mode in modes :
1031+ with self .subTest (mode = mode ):
1032+ self .assertEqual (realpath (path , strict = mode ),
1033+ ABSTFN + expected )
10311034 else :
1032- with self .assertRaises (expected ) as cm :
1033- realpath (path , strict = mode )
1034- if errno is not None :
1035- self .assertEqual (cm .exception .errno , errno )
1035+ for mode in modes :
1036+ with self .subTest (mode = mode ):
1037+ with self .assertRaises (expected ) as cm :
1038+ realpath (path , strict = mode )
1039+ if errno is not None :
1040+ self .assertEqual (cm .exception .errno , errno )
10361041
10371042 self .enterContext (os_helper .change_cwd (ABSTFN ))
1038- check ("file" , False , "/file" )
1039- check ("file" , ALLOW_MISSING , "/file" )
1040- check ("file" , ALL_BUT_LAST , "/file" )
1041- check ("file" , True , "/file" )
1042- check ("file/" , False , "/file" )
1043- check ("file/" , ALLOW_MISSING , "/file" )
1044- check ("file/" , ALL_BUT_LAST , "/file" )
1045- check ("file/" , True , "/file" )
1046- check ("file/file2" , False , "/file/file2" )
1047- check ("file/file2" , ALLOW_MISSING , "/file/file2" )
1048- check ("file/file2" , ALL_BUT_LAST , FileNotFoundError )
1049- check ("file/file2" , True , FileNotFoundError )
1050- check ("file/." , False , "/file" )
1051- check ("file/." , ALLOW_MISSING , "/file" )
1052- check ("file/." , ALL_BUT_LAST , "/file" )
1053- check ("file/." , True , "/file" )
1054- check ("file/../link2" , False , "/dir" )
1055- check ("file/../link2" , ALLOW_MISSING , "/dir" )
1056- check ("file/../link2" , ALL_BUT_LAST , "/dir" )
1057- check ("file/../link2" , True , "/dir" )
1058-
1059- check ("dir" , False , "/dir" )
1060- check ("dir" , ALLOW_MISSING , "/dir" )
1061- check ("dir" , ALL_BUT_LAST , "/dir" )
1062- check ("dir" , True , "/dir" )
1063- check ("dir/" , False , "/dir" )
1064- check ("dir/" , ALLOW_MISSING , "/dir" )
1065- check ("dir/" , ALL_BUT_LAST , "/dir" )
1066- check ("dir/" , True , "/dir" )
1067- check ("dir/file2" , False , "/dir/file2" )
1068- check ("dir/file2" , ALLOW_MISSING , "/dir/file2" )
1069- check ("dir/file2" , ALL_BUT_LAST , "/dir/file2" )
1070- check ("dir/file2" , True , "/dir/file2" )
1071-
1072- check ("link" , False , "/file" )
1073- check ("link" , ALLOW_MISSING , "/file" )
1074- check ("link" , ALL_BUT_LAST , "/file" )
1075- check ("link" , True , "/file" )
1076- check ("link/" , False , "/file" )
1077- check ("link/" , ALLOW_MISSING , "/file" )
1078- check ("link/" , ALL_BUT_LAST , "/file" )
1079- check ("link/" , True , "/file" )
1080- check ("link/file2" , False , "/file/file2" )
1081- check ("link/file2" , ALLOW_MISSING , "/file/file2" )
1082- check ("link/file2" , ALL_BUT_LAST , FileNotFoundError )
1083- check ("link/file2" , True , FileNotFoundError )
1084- check ("link/." , False , "/file" )
1085- check ("link/." , ALLOW_MISSING , "/file" )
1086- check ("link/." , ALL_BUT_LAST , "/file" )
1087- check ("link/." , True , "/file" )
1088- check ("link/../link" , False , "/file" )
1089- check ("link/../link" , ALLOW_MISSING , "/file" )
1090- check ("link/../link" , ALL_BUT_LAST , "/file" )
1091- check ("link/../link" , True , "/file" )
1092-
1093- check ("link2" , False , "/dir" )
1094- check ("link2" , ALLOW_MISSING , "/dir" )
1095- check ("link2" , ALL_BUT_LAST , "/dir" )
1096- check ("link2" , True , "/dir" )
1097- check ("link2/" , False , "/dir" )
1098- check ("link2/" , ALLOW_MISSING , "/dir" )
1099- check ("link2/" , ALL_BUT_LAST , "/dir" )
1100- check ("link2/" , True , "/dir" )
1101- check ("link2/file2" , False , "/dir/file2" )
1102- check ("link2/file2" , ALLOW_MISSING , "/dir/file2" )
1103- check ("link2/file2" , ALL_BUT_LAST , "/dir/file2" )
1104- check ("link2/file2" , True , "/dir/file2" )
1105-
1106- check ("nonexistent" , False , "/nonexistent" )
1107- check ("nonexistent" , ALLOW_MISSING , "/nonexistent" )
1108- check ("nonexistent" , ALL_BUT_LAST , "/nonexistent" )
1109- check ("nonexistent" , True , FileNotFoundError )
1110- check ("nonexistent/" , False , "/nonexistent" )
1111- check ("nonexistent/" , ALLOW_MISSING , "/nonexistent" )
1112- check ("nonexistent/" , ALL_BUT_LAST , "/nonexistent" )
1113- check ("nonexistent/" , True , FileNotFoundError )
1114- check ("nonexistent/file" , False , "/nonexistent/file" )
1115- check ("nonexistent/file" , ALLOW_MISSING , "/nonexistent/file" )
1116- check ("nonexistent/file" , ALL_BUT_LAST , FileNotFoundError )
1117- check ("nonexistent/file" , True , FileNotFoundError )
1118- check ("nonexistent/../link" , False , "/file" )
1119- check ("nonexistent/../link" , ALLOW_MISSING , "/file" )
1120- check ("nonexistent/../link" , ALL_BUT_LAST , "/file" )
1121- check ("nonexistent/../link" , True , "/file" )
1122-
1123- check ("broken" , False , "/nonexistent" )
1124- check ("broken" , ALLOW_MISSING , "/nonexistent" )
1125- check ("broken" , ALL_BUT_LAST , "/nonexistent" )
1126- check ("broken" , True , FileNotFoundError )
1127- check ("broken/" , False , "/nonexistent" )
1128- check ("broken/" , ALLOW_MISSING , "/nonexistent" )
1129- check ("broken/" , ALL_BUT_LAST , "/nonexistent" )
1130- check ("broken/" , True , FileNotFoundError )
1131- check ("broken/file" , False , "/nonexistent/file" )
1132- check ("broken/file" , ALLOW_MISSING , "/nonexistent/file" )
1133- check ("broken/file" , ALL_BUT_LAST , FileNotFoundError )
1134- check ("broken/file" , True , FileNotFoundError )
1135- check ("broken/../link" , False , "/file" )
1136- check ("broken/../link" , ALLOW_MISSING , "/file" )
1137- check ("broken/../link" , ALL_BUT_LAST , "/file" )
1138- check ("broken/../link" , True , "/file" )
1139-
1140- check ("cycle" , False , "/cycle" )
1141- check ("cycle" , ALLOW_MISSING , OSError , errno .EINVAL )
1142- check ("cycle" , ALL_BUT_LAST , OSError , errno .EINVAL )
1143- check ("cycle" , True , OSError , errno .EINVAL )
1144- check ("cycle/" , False , "/cycle" )
1145- check ("cycle/" , ALLOW_MISSING , OSError , errno .EINVAL )
1146- check ("cycle/" , ALL_BUT_LAST , OSError , errno .EINVAL )
1147- check ("cycle/" , True , OSError , errno .EINVAL )
1148- check ("cycle/file" , False , "/cycle/file" )
1149- check ("cycle/file" , ALLOW_MISSING , OSError , errno .EINVAL )
1150- check ("cycle/file" , ALL_BUT_LAST , OSError , errno .EINVAL )
1151- check ("cycle/file" , True , OSError , errno .EINVAL )
1152- check ("cycle/../link" , False , "/file" )
1153- check ("cycle/../link" , ALLOW_MISSING , "/file" )
1154- check ("cycle/../link" , ALL_BUT_LAST , "/file" )
1155- check ("cycle/../link" , True , "/file" )
1043+ all_modes = [False , ALLOW_MISSING , ALL_BUT_LAST , True ]
1044+ check ("file" , all_modes , "/file" )
1045+ check ("file/" , all_modes , "/file" )
1046+ check ("file/file2" , [False , ALLOW_MISSING ], "/file/file2" )
1047+ check ("file/file2" , [ALL_BUT_LAST , True ], FileNotFoundError )
1048+ check ("file/." , all_modes , "/file" )
1049+ check ("file/../link2" , all_modes , "/dir" )
1050+
1051+ check ("dir" , all_modes , "/dir" )
1052+ check ("dir/" , all_modes , "/dir" )
1053+ check ("dir/file2" , all_modes , "/dir/file2" )
1054+
1055+ check ("link" , all_modes , "/file" )
1056+ check ("link/" , all_modes , "/file" )
1057+ check ("link/file2" , [False , ALLOW_MISSING ], "/file/file2" )
1058+ check ("link/file2" , [ALL_BUT_LAST , True ], FileNotFoundError )
1059+ check ("link/." , all_modes , "/file" )
1060+ check ("link/../link" , all_modes , "/file" )
1061+
1062+ check ("link2" , all_modes , "/dir" )
1063+ check ("link2/" , all_modes , "/dir" )
1064+ check ("link2/file2" , all_modes , "/dir/file2" )
1065+
1066+ check ("nonexistent" , [False , ALLOW_MISSING , ALL_BUT_LAST ], "/nonexistent" )
1067+ check ("nonexistent" , [True ], FileNotFoundError )
1068+ check ("nonexistent/" , [False , ALLOW_MISSING , ALL_BUT_LAST ], "/nonexistent" )
1069+ check ("nonexistent/" , [True ], FileNotFoundError )
1070+ check ("nonexistent/file" , [False , ALLOW_MISSING ], "/nonexistent/file" )
1071+ check ("nonexistent/file" , [ALL_BUT_LAST , True ], FileNotFoundError )
1072+ check ("nonexistent/../link" , all_modes , "/file" )
1073+
1074+ check ("broken" , [False , ALLOW_MISSING , ALL_BUT_LAST ], "/nonexistent" )
1075+ check ("broken" , [True ], FileNotFoundError )
1076+ check ("broken/" , [False , ALLOW_MISSING , ALL_BUT_LAST ], "/nonexistent" )
1077+ check ("broken/" , [True ], FileNotFoundError )
1078+ check ("broken/file" , [False , ALLOW_MISSING ], "/nonexistent/file" )
1079+ check ("broken/file" , [ALL_BUT_LAST , True ], FileNotFoundError )
1080+ check ("broken/../link" , all_modes , "/file" )
1081+
1082+ check ("cycle" , [False ], "/cycle" )
1083+ check ("cycle" , [ALLOW_MISSING , ALL_BUT_LAST , True ], OSError , errno .EINVAL )
1084+ check ("cycle/" , [False ], "/cycle" )
1085+ check ("cycle/" , [ALLOW_MISSING , ALL_BUT_LAST , True ], OSError , errno .EINVAL )
1086+ check ("cycle/file" , [False ], "/cycle/file" )
1087+ check ("cycle/file" , [ALLOW_MISSING , ALL_BUT_LAST , True ], OSError , errno .EINVAL )
1088+ check ("cycle/../link" , all_modes , "/file" )
11561089
11571090 def test_expandvars (self ):
11581091 with os_helper .EnvironmentVarGuard () as env :
0 commit comments