コード例 #1
0
ファイル: test_path.py プロジェクト: pombredanne/ffs-1
 def test_ls_nonexistant(self):
     "Should raise if we don't exist"
     nopath = tempfile.mkdtemp()
     rmdir(nopath)
     p = Path(nopath)
     with self.assertRaises(exceptions.DoesNotExistError):
         p.ls()
コード例 #2
0
ファイル: test_path.py プロジェクト: davidmiller/ffs
 def test_ls_nonexistant(self):
     "Should raise if we don't exist"
     nopath = tempfile.mkdtemp()
     rmdir(nopath)
     p = Path(nopath)
     with self.assertRaises(exceptions.DoesNotExistError):
         p.ls()
コード例 #3
0
ファイル: test_path.py プロジェクト: davidmiller/ffs
 def test_iter_raises(self):
     "Iterate through lines in a file"
     nopath = tempfile.mkdtemp()
     rmdir(nopath)
     p = Path(nopath)
     with self.assertRaises(exceptions.DoesNotExistError):
         for branch in p:
             raise AssertionError("Shouldn't get this far")
コード例 #4
0
ファイル: test_path.py プロジェクト: pombredanne/ffs-1
 def test_iter_raises(self):
     "Iterate through lines in a file"
     nopath = tempfile.mkdtemp()
     rmdir(nopath)
     p = Path(nopath)
     with self.assertRaises(exceptions.DoesNotExistError):
         for branch in p:
             raise AssertionError("Shouldn't get this far")
コード例 #5
0
ファイル: test_path.py プロジェクト: davidmiller/ffs
 def test_open_mkpath(self):
     "If we open a path that doesn't exist yet, make it"
     nopath = tempfile.mkdtemp()
     rmdir(nopath)
     p = Path(nopath) + 'really/doesnt/exist.txt'
     filename = nopath + '/really/doesnt/exist.txt'
     with p.open('w') as fh:
         self.assertIsInstance(fh, FileKlass)
         self.assertEqual(filename, fh.name)
     pass
コード例 #6
0
ファイル: test_path.py プロジェクト: pombredanne/ffs-1
 def test_open_mkpath(self):
     "If we open a path that doesn't exist yet, make it"
     nopath = tempfile.mkdtemp()
     rmdir(nopath)
     p = Path(nopath) + 'really/doesnt/exist.txt'
     filename = nopath + '/really/doesnt/exist.txt'
     with p.open('w') as fh:
         self.assertIsInstance(fh, FileKlass)
         self.assertEqual(filename, fh.name)
     pass
コード例 #7
0
ファイル: test_nix.py プロジェクト: pombredanne/ffs-1
 def test_mkdirs(self):
     "Make all the directories"
     second = tempfile.mkdtemp()
     nix.rmdir(second)
     self.assertFalse(os.path.exists(self.nodir))
     self.assertFalse(os.path.exists(second))
     try:
         nix.mkdir(self.nodir, second)
         self.assertTrue(os.path.exists(self.nodir))
         self.assertTrue(os.path.exists(second))
     finally:
         try:
             nix.rmdir(second)
         except OSError:
             pass
コード例 #8
0
ファイル: test_nix.py プロジェクト: davidmiller/ffs
 def test_mkdirs(self):
     "Make all the directories"
     second = tempfile.mkdtemp()
     nix.rmdir(second)
     self.assertFalse(os.path.exists(self.nodir))
     self.assertFalse(os.path.exists(second))
     try:
         nix.mkdir(self.nodir, second)
         self.assertTrue(os.path.exists(self.nodir))
         self.assertTrue(os.path.exists(second))
     finally:
         try:
             nix.rmdir(second)
         except OSError:
             pass
コード例 #9
0
ファイル: archive.py プロジェクト: davidmiller/ffs
    def __lshift__(self, contents):
        """
        we overload the << operator to allow us easy file writing according to the
        following rules:

        if contents is not a stringtype, raise TypeError.

        otherwise, treat self like a file and append contents to it.

        note::

            if components of the path leading to self do not exist,
            they will be created. it is assumed that the user knows their
            own mind.

        arguments:
        - `contents`: stringtype

        return: None
        exceptions: TypeError
        """
        if not isinstance(contents, six.string_types):
            raise TypeError("you have to write with a stringtype larry... ")
        temp = path.Path.newdir()
        FOUND = False

        with zipfile.ZipFile(self._archive, 'r') as rz:
            with zipfile.ZipFile(temp/'tmp.zip', 'w') as wz:
                for info in rz.infolist():
                    content = rz.open(info).read()
                    if info.filename == self._inner_value:
                        FOUND = True
                        content += "\n"+contents
                    wz.writestr(info, content)
                if not FOUND:
                    wz.writestr(self._inner_value, contents)
        nix.mv(temp/'tmp.zip', self._archive)
        nix.rmdir(temp)
        return
コード例 #10
0
    def __lshift__(self, contents):
        """
        we overload the << operator to allow us easy file writing according to the
        following rules:

        if contents is not a stringtype, raise TypeError.

        otherwise, treat self like a file and append contents to it.

        note::

            if components of the path leading to self do not exist,
            they will be created. it is assumed that the user knows their
            own mind.

        arguments:
        - `contents`: stringtype

        return: None
        exceptions: TypeError
        """
        if not isinstance(contents, six.string_types):
            raise TypeError("you have to write with a stringtype larry... ")
        temp = path.Path.newdir()
        FOUND = False

        with zipfile.ZipFile(self._archive, 'r') as rz:
            with zipfile.ZipFile(temp / 'tmp.zip', 'w') as wz:
                for info in rz.infolist():
                    content = rz.open(info).read()
                    if info.filename == self._inner_value:
                        FOUND = True
                        content += "\n" + contents
                    wz.writestr(info, content)
                if not FOUND:
                    wz.writestr(self._inner_value, contents)
        nix.mv(temp / 'tmp.zip', self._archive)
        nix.rmdir(temp)
        return
コード例 #11
0
ファイル: test_nix.py プロジェクト: pombredanne/ffs-1
 def setUp(self):
     self.nopath = tempfile.mkdtemp()
     nix.rmdir(self.nopath)
コード例 #12
0
ファイル: test_nix.py プロジェクト: pombredanne/ffs-1
 def setUp(self):
     self.nodir = tempfile.mkdtemp()
     nix.rmdir(self.nodir)
コード例 #13
0
ファイル: test_nix.py プロジェクト: davidmiller/ffs
 def setUp(self):
     self.nopath = tempfile.mkdtemp()
     nix.rmdir(self.nopath)
コード例 #14
0
ファイル: test_nix.py プロジェクト: davidmiller/ffs
 def setUp(self):
     self.nodir = tempfile.mkdtemp()
     nix.rmdir(self.nodir)