def test_mustexist(self): with self.assert_raises(ValueError, 'No such file or directory'): Path('/foo/bar/baz', mustexist=True) existing_path = __file__ p = Path(existing_path, mustexist=True) self.assertEqual(repr(p), repr(__file__))
def test_parsing_tilde(self): homedir = os.environ['HOME'] self.assertEqual(Path('~/foo/bar'), os.path.join(homedir, 'foo/bar')) self.assertEqual(str(Path('~/foo/bar')), os.path.join(homedir, 'foo/bar')) self.assertEqual(repr(Path('~/foo/bar')), repr(os.path.join(homedir, 'foo/bar')))
def test_base_with_tilde(self): p = Path('bar/baz', base='~/foo') self.assertEqual(p, 'bar/baz') self.assertEqual(p.base_path, os.path.join(os.environ['HOME'], 'foo')) self.assertEqual(p.full_path, os.path.join(os.environ['HOME'], 'foo/bar/baz')) self.assertIsInstance(p.full_path, type(p))
def test_path_with_current_directory_ignores_base(self): import os p = Path('./bar/baz', base='/foo') self.assertEqual(p, 'bar/baz') self.assertEqual(p.base_path, '/foo') self.assertEqual(p.full_path, 'bar/baz') self.assertIsInstance(p.full_path, type(p))
def test_hidden_files_do_not_ignore_base(self): p = Path('.baz', base='foo/bar') self.assertEqual(p, '.baz') self.assertEqual(p.base_path, 'foo/bar') self.assertEqual(p.full_path, 'foo/bar/.baz') self.assertIsInstance(p.full_path, type(p))
def test_path_with_upper_level_directory_ignores_base(self): p = Path('../baz', base='/foo/bar') self.assertEqual(p, '../baz') self.assertEqual(p.base_path, '/foo/bar') self.assertEqual(p.full_path, '../baz') self.assertIsInstance(p.full_path, type(p))
def test_prettified(self): p = Path(os.path.join(os.environ['HOME'], 'foo/bar')) self.assertEqual(p.prettified, '~/foo/bar')
def test_syntax(self): self.assertEqual(Path('/foo/bar/baz').syntax, 'file system path')
def test_prettified(self): import os homedir = os.environ['HOME'] p = Path(os.path.join(homedir, 'foo/bar')) self.assertEqual(p.prettified, '~/foo/bar')