def testExplicitModuleClasses(self): """ Multiple calls to path.using_module should produce the same class. """ nt_path = path.using_module(ntpath) self.assert_(nt_path is path.using_module(ntpath)) self.assertEqual(nt_path.__name__, 'path_ntpath')
def testExplicitModule(self): nt_ok = path.using_module(ntpath, r'foo\bar\baz') posix_ok = path.using_module(posixpath, r'foo/bar/baz') posix_wrong = path.using_module(posixpath, r'foo\bar\baz') self.assertEqual(nt_ok.dirname(), r'foo\bar') self.assertEqual(posix_ok.dirname(), r'foo/bar') self.assertEqual(posix_wrong.dirname(), '') self.assertEqual(nt_ok / 'quux', r'foo\bar\baz\quux') self.assertEqual(posix_ok / 'quux', r'foo/bar/baz/quux')
def testExplicitModule(self): """ The user may specify an explicit path module to use. """ nt_ok = path.using_module(ntpath)(r'foo\bar\baz') posix_ok = path.using_module(posixpath)(r'foo/bar/baz') posix_wrong = path.using_module(posixpath)(r'foo\bar\baz') self.assertEqual(nt_ok.dirname(), r'foo\bar') self.assertEqual(posix_ok.dirname(), r'foo/bar') self.assertEqual(posix_wrong.dirname(), '') self.assertEqual(nt_ok / 'quux', r'foo\bar\baz\quux') self.assertEqual(posix_ok / 'quux', r'foo/bar/baz/quux')
def testExplicitModule(self): """ The user may specify an explicit path module to use. """ nt_ok = path.using_module(ntpath)(r"foo\bar\baz") posix_ok = path.using_module(posixpath)(r"foo/bar/baz") posix_wrong = path.using_module(posixpath)(r"foo\bar\baz") self.assertEqual(nt_ok.dirname(), r"foo\bar") self.assertEqual(posix_ok.dirname(), r"foo/bar") self.assertEqual(posix_wrong.dirname(), "") self.assertEqual(nt_ok / "quux", r"foo\bar\baz\quux") self.assertEqual(posix_ok / "quux", r"foo/bar/baz/quux")
def test_listdir_custom_module(self, tmpdir): """ Listdir patterns should honor the case sensitivity of the path module used by that path class. """ always_unix = path.using_module(posixpath) p = always_unix(tmpdir) (p/'sub').mkdir() (p/'File').touch() assert p.listdir('S*') == [] always_win = path.using_module(ntpath) p = always_win(tmpdir) assert p.listdir('S*') == [p/'sub'] assert p.listdir('f*') == [p/'File']
def test_joinpath_returns_same_type(self): path_posix = path.using_module(posixpath) res = path_posix.joinpath('foo') assert isinstance(res, path_posix) res2 = res.joinpath('bar') assert isinstance(res2, path_posix) assert res2 == 'foo/bar'