Exemplo n.º 1
0
    def test_delete_false_makes_file_not_disappear_when_garbage_collected(
            self, fsx_fake):
        def scope():
            file_ = fsx.tempfile.NamedTemporaryFile(delete=False)
            return file_.name

        path = scope()
        assert fsx.exists(path) == True
Exemplo n.º 2
0
def _get_new_path(dir, prefix, suffix):
    ''' Extracted from `tempfile.py` to build proper temp-paths. '''
    names = tempfile._get_candidate_names()

    for seq in six.moves.xrange(tempfile.TMP_MAX):
        name = next(names)
        res = os.path.join(dir, prefix + name + suffix)
        if fsx.exists(res):
            continue
        return res

    raise IOError(errno.EEXIST, "No usable temporary file name found")
Exemplo n.º 3
0
 def test_delete_false_makes_file_disappear(self, fsx_fake):
     with fsx.tempfile.NamedTemporaryFile(delete=False) as file_:
         pass
     assert fsx.exists(file_.name) == True
Exemplo n.º 4
0
 def test_delete_true_makes_file_disappear_after_close(self, fsx_fake):
     file_ = fsx.tempfile.NamedTemporaryFile(delete=True)
     file_.close()
     assert fsx.exists(file_.name) == False
Exemplo n.º 5
0
 def test_delete_false_makes_file_persistent(self, fsx_fake):
     file_ = fsx.tempfile.NamedTemporaryFile(delete=False)
     assert fsx.exists(file_.name) == True
Exemplo n.º 6
0
 def test_ZipFile_writestr_creates_file(self, fsx_fake):
     fsx.zipfile.ZipFile('arch.zip', 'w').writestr('f', 'test')
     assert fsx.exists('arch.zip') == True
Exemplo n.º 7
0
def test_open_write_creates_file(fsx_fake):
    text = 'test'
    fsx.open('f', 'w').write(text)
    assert fsx.exists('f') == True