Beispiel #1
0
    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__))
Beispiel #2
0
 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')))
Beispiel #3
0
 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))
Beispiel #4
0
 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))
Beispiel #5
0
 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))
Beispiel #6
0
 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))
Beispiel #7
0
 def test_prettified(self):
     p = Path(os.path.join(os.environ['HOME'], 'foo/bar'))
     self.assertEqual(p.prettified, '~/foo/bar')
Beispiel #8
0
 def test_syntax(self):
     self.assertEqual(Path('/foo/bar/baz').syntax, 'file system path')
Beispiel #9
0
 def test_prettified(self):
     import os
     homedir = os.environ['HOME']
     p = Path(os.path.join(homedir, 'foo/bar'))
     self.assertEqual(p.prettified, '~/foo/bar')