def test_size(): with temporary_dir() as td: create_files(td, 'file1.txt') file1 = os.path.join(td, 'file1.txt') assert safe_size(file1) == 0 with open(file1, 'w') as fp: fp.write('!' * 101) assert safe_size(file1) == 101 f1stat = os.stat(file1) assert safe_bsize(file1) == 512 * f1stat.st_blocks assert du(td) == safe_bsize(file1) file2 = os.path.join(td, 'file2.txt') os.symlink('file1.txt', file2) assert safe_size(file2) == len('file1.txt') assert safe_bsize(file2) == len('file1.txt') assert du(td) == safe_bsize(file1) + len('file1.txt') assert safe_size(os.path.join(td, 'file3.txt')) == 0 assert safe_bsize(os.path.join(td, 'file3.txt')) == 0 errors = [] def on_error(path, err): errors.append(path) safe_size(os.path.join(td, 'file3.txt'), on_error=on_error) assert errors == [os.path.join(td, 'file3.txt')]
def run(self): log.debug("DiskCollectorThread: starting collection of %s" % self.path) self.value = du(self.path) log.debug("DiskCollectorThread: finished collection of %s" % self.path) self.event.set()
def run(self): start = time.time() self.value = du(self.path) log.debug("DiskCollectorThread: finished collection of %s in %.1fms" % ( self.path, 1000.0 * (time.time() - start))) self.event.set()
def run(self): start = time.time() self.value = du(self._path) log.debug("DuDiskCollectorThread: finished collection of %s in %.1fms", self._path, 1000.0 * (time.time() - start)) self.event.set()