Exemple #1
0
 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()
Exemple #2
0
 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()
Exemple #3
0
 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")
Exemple #4
0
 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")
Exemple #5
0
 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
Exemple #6
0
 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
Exemple #7
0
 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
Exemple #8
0
 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
Exemple #9
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
Exemple #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
Exemple #11
0
 def setUp(self):
     self.nopath = tempfile.mkdtemp()
     nix.rmdir(self.nopath)
Exemple #12
0
 def setUp(self):
     self.nodir = tempfile.mkdtemp()
     nix.rmdir(self.nodir)
Exemple #13
0
 def setUp(self):
     self.nopath = tempfile.mkdtemp()
     nix.rmdir(self.nopath)
Exemple #14
0
 def setUp(self):
     self.nodir = tempfile.mkdtemp()
     nix.rmdir(self.nodir)