Пример #1
0
 def test_default_is_zero(self):
     flen = 1024
     myfile = self.tmp_path("def_zero")
     util.write_file(myfile, flen * b'\1', omode="wb")
     block.wipe_file(myfile)
     found = util.load_file(myfile, decode=False)
     self.assertEqual(found, flen * b'\0')
Пример #2
0
 def test_non_exist_dir_raises_file_not_found(self):
     try:
         p = self.tmp_path(os.path.sep.join(["enodir", "file"]))
         block.wipe_file(p)
         raise Exception("%s did not raise exception" % p)
     except Exception as e:
         if not util.is_file_not_found_exc(e):
             raise Exception("exc was not file_not_found: %s" % e)
Пример #3
0
 def test_non_exist_raises_file_not_found(self):
     try:
         p = self.tmp_path("enofile")
         block.wipe_file(p)
         raise Exception("%s did not raise exception" % p)
     except Exception as e:
         if not util.is_file_not_found_exc(e):
             raise Exception("exc was not file_not_found: %s" % e)
Пример #4
0
 def test_reader_fhandle(self):
     srcfile = self.tmp_path("fhandle_src")
     trgfile = self.tmp_path("fhandle_trg")
     data = '\n'.join(["this is source file." for f in range(0, 10)] + [])
     util.write_file(srcfile, data)
     util.write_file(trgfile, 'a' * len(data))
     with open(srcfile, "rb") as fp:
         block.wipe_file(trgfile, reader=fp.read)
     found = util.load_file(trgfile)
     self.assertEqual(data, found)
Пример #5
0
    def test_reader_used(self):
        flen = 17

        def reader(size):
            return size * b'\1'

        myfile = self.tmp_path("reader_used")
        # populate with nulls
        util.write_file(myfile, flen * b'\0', omode="wb")
        block.wipe_file(myfile, reader=reader, buflen=flen)
        found = util.load_file(myfile, decode=False)
        self.assertEqual(found, flen * b'\1')
Пример #6
0
    def test_reader_twice(self):
        flen = 37
        data = {'x': 20 * b'a' + 20 * b'b'}
        expected = data['x'][0:flen]

        def reader(size):
            buf = data['x'][0:size]
            data['x'] = data['x'][size:]
            return buf

        myfile = self.tmp_path("reader_twice")
        util.write_file(myfile, flen * b'\xff', omode="wb")
        block.wipe_file(myfile, reader=reader, buflen=20)
        found = util.load_file(myfile, decode=False)
        self.assertEqual(found, expected)