MCPcopy Index your code
hub / github.com/RustPython/RustPython / glob

Method glob

Lib/test/test_glob.py:61–109  ·  view source on GitHub ↗
(self, *parts, **kwargs)

Source from the content-addressed store, hash-verified

59 shutil.rmtree(self.tempdir)
60
61 def glob(self, *parts, **kwargs):
62 if len(parts) == 1:
63 pattern = parts[0]
64 else:
65 pattern = os.path.join(*parts)
66 p = os.path.join(self.tempdir, pattern)
67 res = glob.glob(p, **kwargs)
68 res2 = glob.iglob(p, **kwargs)
69 self.assertCountEqual(glob.iglob(p, **kwargs), res)
70
71 bres = [os.fsencode(x) for x in res]
72 self.assertCountEqual(glob.glob(os.fsencode(p), **kwargs), bres)
73 self.assertCountEqual(glob.iglob(os.fsencode(p), **kwargs), bres)
74
75 with change_cwd(self.tempdir):
76 res2 = glob.glob(pattern, **kwargs)
77 for x in res2:
78 self.assertFalse(os.path.isabs(x), x)
79 if pattern == '**' or pattern == '**' + os.sep:
80 expected = res[1:]
81 else:
82 expected = res
83 self.assertCountEqual([os.path.join(self.tempdir, x) for x in res2],
84 expected)
85 self.assertCountEqual(glob.iglob(pattern, **kwargs), res2)
86 bpattern = os.fsencode(pattern)
87 bres2 = [os.fsencode(x) for x in res2]
88 self.assertCountEqual(glob.glob(bpattern, **kwargs), bres2)
89 self.assertCountEqual(glob.iglob(bpattern, **kwargs), bres2)
90
91 self.assertCountEqual(glob.glob(pattern, root_dir=self.tempdir, **kwargs), res2)
92 self.assertCountEqual(glob.iglob(pattern, root_dir=self.tempdir, **kwargs), res2)
93 btempdir = os.fsencode(self.tempdir)
94 self.assertCountEqual(
95 glob.glob(bpattern, root_dir=btempdir, **kwargs), bres2)
96 self.assertCountEqual(
97 glob.iglob(bpattern, root_dir=btempdir, **kwargs), bres2)
98
99 if self.dir_fd is not None:
100 self.assertCountEqual(
101 glob.glob(pattern, dir_fd=self.dir_fd, **kwargs), res2)
102 self.assertCountEqual(
103 glob.iglob(pattern, dir_fd=self.dir_fd, **kwargs), res2)
104 self.assertCountEqual(
105 glob.glob(bpattern, dir_fd=self.dir_fd, **kwargs), bres2)
106 self.assertCountEqual(
107 glob.iglob(bpattern, dir_fd=self.dir_fd, **kwargs), bres2)
108
109 return res
110
111 def assertSequencesEqual_noorder(self, l1, l2):
112 l1 = list(l1)

Callers 15

test_glob_literalMethod · 0.95
test_glob_symlinksMethod · 0.95
rglobMethod · 0.95
hglobMethod · 0.95
test_random_filesMethod · 0.45
BaseTestClass · 0.45
files_to_testMethod · 0.45
test_getlongpathnameMethod · 0.45

Calls 6

change_cwdFunction · 0.90
lenFunction · 0.85
assertCountEqualMethod · 0.80
fsencodeMethod · 0.80
assertFalseMethod · 0.80
joinMethod · 0.45

Tested by

no test coverage detected