def test_ls_dotfile(self): "Shouldn't see dotfiles" nix.touch(Path(self.tdir) + '.dotrc') self.assertTrue(os.path.isfile(self.tdir + '/.dotrc')) contents = nix.ls(Path(self.tdir)) contents.sort() self.assertEqual(['bar.txt', 'foo.txt'], contents)
def test_recursive_contents(self): """ This was caused by ending up with a Path as _value, not catching it in __init__. """ p = Path(self.tdir) + 'some.txt' p.touch() p2 = Path(p) self.assertEqual('', p2.contents)
def test_mv_target_exists(self): "Should just overwrite" one = Path(str(self.tpath) + '//one.txt') two = Path(str(self.tpath) + '//two.txt') one << 'Contentz' two << 'Contentz Two' target = str(two) self.assertTrue(os.path.exists(target)) nix.mv(str(one), target) self.assertTrue(os.path.exists(target)) self.assertFalse(os.path.exists(str(one))) self.assertEqual('Contentz', two.contents)
def test_ls_almost_all(self): "Should see most dotfiles" nix.touch(Path(self.tdir) + '.dotrc') self.assertTrue(os.path.isfile(self.tdir + '/.dotrc')) contents = nix.ls(self.tdir, almost_all=True) contents.sort() self.assertEqual(['.dotrc', 'bar.txt', 'foo.txt'], contents)
def test_accepts_path(self): "Should Duck-type with Path objects" nix.cd(Path('/tmp')) cwd = os.getcwd() if sys.platform == 'darwin': cwd = cwd.replace('/private', '') self.assertEqual('/tmp', cwd)
def test_ls_a_ignore_backups(self): "Should ignore ~ files even with all" nix.touch(Path(self.tdir) + 'dotrc~') self.assertTrue(os.path.isfile(self.tdir + '/dotrc~')) contents = nix.ls(self.tdir, ignore_backups=True, all=True) contents.sort() self.assertEqual(['.', '..', 'bar.txt', 'foo.txt'], contents)
def test_ln_path(self): "Should link path objects" dest = Path(self.tdir) dest += 'hardlink' nix.ln(self.src, dest) self.assertTrue(os.path.isfile(str(dest))) self.assertTrue(filecmp.cmp(self.src, str(dest))) self.assertFalse(os.path.islink(str(dest)))
def __enter__(self): """ Contextmanager protocol initialization. Returns a Path representing the current working directory """ from ffs import Path return Path(self.path)
def test_force(self): "Force for non-empty dest" dest = Path(self.tdir) + 'hardlink' dest << 'contentz' self.assertEqual('contentz', dest.contents) nix.ln(self.src, dest, force=True) self.assertNotEqual('contentz', dest.contents) self.assertTrue(os.path.isfile(str(dest))) self.assertTrue(filecmp.cmp(self.src, str(dest))) self.assertFalse(os.path.islink(str(dest)))
def setUp(self): self.tdir = Path(tempfile.mkdtemp())
def test_touch_path(self): "Create from a Path object" filestr = self.tdir + '/foo.txt' filepath = Path(filestr) nix.touch(filepath) self.assertTrue(os.path.isfile(filestr))
def test_rm_path(self): "Remove a Path" self.assertTrue(os.path.exists(self.newfile)) nix.rm(Path(self.newfile)) self.assertFalse(os.path.exists(self.newfile))
def test_chown_path(self): "Can we chown a path?" with patch.object(nix.os, 'chown') as pchown: nix.chown(Path('/hai'), uid=100) pchown.assert_called_once_with('/hai', 100, -1)
def setUp(self): self.tpath = Path(tempfile.mkdtemp())
def test_mkdirp_path(self): "Should accept Path objects" p = Path(self.nopath) + 'some/long/structure' nix.mkdir_p(p) self.assertTrue(os.path.isdir(self.nopath + '/some/long/structure'))
def test_mkdir_parents_false(self): "Should raise" self.assertFalse(os.path.exists(self.nodir)) p = Path(self.nodir) + 'child/leaves' with self.assertRaises(exceptions.BadParentingError): nix.mkdir(p, parents=False)
def test_ln_dest_exists(self): "Raise if dest exists" dest = Path(self.tdir) + '/hardlink' dest.touch() with self.assertRaises(exceptions.ExistsError): nix.ln(self.src, dest)
def test_div_unicode_withformatting(self): "Should just join the paths." p = Path('/tmp') p = p / six.u('foo') / '{0}.xml'.format(six.u('bar')) self.assertEqual('/tmp/foo/bar.xml', p)
def test_with_path(self): "Should work with Path objects" nix.chmod(Path(self.tname), 644) self.assertEqual(33412, os.stat(self.tname).st_mode)
def test_path(self): "Should take Path objects" expected = "\n".join([str(x) for x in range(10)]) + "\n" frist = nix.head(Path(self.tname)) self.assertEqual(expected, frist)
def test_ls_path(self): "list files in dir" contents = nix.ls(Path(self.tdir)) contents.sort() self.assertEqual(['bar.txt', 'foo.txt'], contents)
def setUp(self): self.tdir = tempfile.mkdtemp() p = Path(self.tdir) nix.touch(p + 'foo.txt') nix.touch(p + 'bar.txt')
def test_ospathjoin_immutability(self): "os.path.join on a path shouldn't change it." p = Path('/tmp') p2 = os.path.join(p, 'foo') self.assertEqual('/tmp', p) self.assertEqual('/tmp/foo', p2)
def test_mkdir_path(self): "Should make a directory from a Path()" self.assertFalse(os.path.exists(self.nodir)) nix.mkdir(Path(self.nodir)) self.assertTrue(os.path.exists(self.nodir))
def test_rstrip(self): "Rstrip should be available. (shutil.move)" p = Path('/tmp/foo/bar/') bn = shutil._basename(p) self.assertEqual('bar', bn)
def test_mkdir_parents(self): "make all parent dirs" self.assertFalse(os.path.exists(self.nodir)) p = Path(self.nodir) + 'child/leaves' nix.mkdir(p, parents=True) self.assertTrue(os.path.exists(self.nodir))
def test_os_path_split(self): "should split it" p = Path('/tmp/my.file') splat = os.path.split(p) self.assertEqual('/tmp', splat[0]) self.assertEqual('my.file', splat[1])
def setUp(self): self.tfile = tempfile.mktemp() self.tcsv = Path(self.tfile) self.tcsv << '1,2,3,4'