def test_listdir_symlinks_nofollow(self): """listdir: symbolic links in tree not followed Similar assumptions as in test_listdir_nosymlinks, except the directory structure looks like this: $ tree tests/listdir_symlinks tests/listdir_symlinks |-- 10_byte_file_link -> ../listdir/10_byte_file `-- depth1 `-- depth2 `-- 10_byte_file 2 directories, 2 files """ # Call with relpath=True so the paths are easier to verify contents = list( bitmath.listdir('./tests/listdir_symlinks/', relpath=True)) # Ensure the returned path matches the expected path self.assertEqual(contents[0][0], 'tests/listdir_symlinks/depth1/depth2/10_byte_file') # Ensure the measured size is what we expect self.assertEqual(contents[0][1], bitmath.Byte(10.0))
def test_listdir_symlinks_follow_relpath_false(self): """listdir: symlinks followed, absolute paths are returned Same assumptions as in test_listdir_symlinks_follow. Difference is that the 0th item of the tuple returns a fully qualified path. """ contents = list(bitmath.listdir('./tests/listdir_symlinks/', followlinks=True)) # Ensure the returned path matches the expected path and # begins with the present working directory pwd = os.path.realpath('.') expected_paths = [ os.path.join(pwd, contents[0][0]), os.path.join(pwd, contents[1][0]) ] discovered_paths = [ contents[0][0], contents[1][0] ] self.assertListEqual(discovered_paths, expected_paths) # Ensure the measured size is what we expect expected_sizes = [ bitmath.Byte(10.0), bitmath.Byte(10.0) ] discovered_sizes = [ contents[0][1], contents[1][1] ] self.assertListEqual(discovered_sizes, expected_sizes)
def test_listdir_symlinks_follow(self): """listdir: symbolic links in tree are followed Same assumptions as in test_listdir_symlinks_nofollow. """ # Call with relpath=True so the paths are easier to verify contents = list(bitmath.listdir('./tests/listdir_symlinks/', followlinks=True, relpath=True)) # Ensure the returned path matches the expected path expected_paths = [ 'tests/listdir_symlinks/10_byte_file_link', 'tests/listdir_symlinks/depth1/depth2/10_byte_file' ] discovered_paths = [ contents[0][0], contents[1][0] ] self.assertListEqual(discovered_paths, expected_paths) # Ensure the measured size is what we expect expected_sizes = [ bitmath.Byte(10.0), bitmath.Byte(10.0) ] discovered_sizes = [ contents[0][1], contents[1][1] ] self.assertListEqual(discovered_sizes, expected_sizes)
def test_listdir_nosymlinks(self): """listdir: no symbolic links in tree measures right Assume a directory tree where no sub-directories are symbolic links:: $ tree ./tests/listdir_nosymlinks ./tests/listdir_nosymlinks `-- depth1 `-- depth2 |-- 1024_byte_file `-- 10_byte_file 2 directories, 2 files And the files, ``tests/listdir_nosymlinks/depth1/depth2/10_byte_file`` and ``tests/listdir_nosymlinks/depth1/depth2/1024_byte_file`` are 10 Bytes and 1024 Bytes in size, respectively. Then: >>> for f in bitmath.listdir('./tests/listdir_nosymlinks'): ... print f Would yield 2-tuple's of: ('/path/tests/listdir_nosymlinks/depth1/depth2/10_byte_file', Byte(10.0)) ('/path/tests/listdir_nosymlinks/depth1/depth2/1024_byte_file', KiB(1.0)) """ # Call with relpath=True so the paths are easier to verify contents = list(bitmath.listdir('./tests/listdir_nosymlinks/', relpath=True)) # Ensure the returned paths match the expected paths discovered_paths = [ contents[0][0], contents[1][0], ] expected_paths = [ 'tests/listdir_nosymlinks/depth1/depth2/10_byte_file', 'tests/listdir_nosymlinks/depth1/depth2/1024_byte_file' ] self.assertListEqual(discovered_paths, expected_paths) expected_sizes = [ bitmath.Byte(10.0), bitmath.Byte(1024.0) ] discovered_sizes = [ contents[0][1], contents[1][1] ] self.assertListEqual(discovered_sizes, expected_sizes)
def test_listdir_filtering_empty_match_nosymlinks(self): """listdir: filtering with nosymlinks returns 0 matches for a filter Same assumptions as test_listdir_nosymlinks.""" # Call with relpath=True so the paths are easier to verify contents = list(bitmath.listdir('./tests/listdir_nosymlinks/', relpath=True, # Should find no matches filter='*notafile*')) # There should be one file discovered self.assertEqual(len(contents), int(0))
def test_listdir_filtering_empty_match_nosymlinks(self): """listdir: filtering with nosymlinks returns 0 matches for a filter Same assumptions as test_listdir_nosymlinks.""" # Call with relpath=True so the paths are easier to verify contents = list( bitmath.listdir( './tests/listdir_nosymlinks/', relpath=True, # Should find no matches filter='*notafile*')) # There should be one file discovered self.assertEqual(len(contents), int(0))
def test_listdir_filtering_nosymlinks(self): """listdir: no symbolic links in tree measures right with a filter Same assumptions as test_listdir_nosymlinks.""" # Call with relpath=True so the paths are easier to verify contents = list(bitmath.listdir('./tests/listdir_nosymlinks/', relpath=True, # Should only find 1 file, 1024_byte_file filter='1024*')) # Ensure the returned path matches the expected path self.assertEqual(contents[0][0], 'tests/listdir_nosymlinks/depth1/depth2/1024_byte_file') # Ensure the measured size is what we expect self.assertEqual(contents[0][1], bitmath.KiB(1.0))
def test_listdir_nosymlinks(self): """listdir: no symbolic links in tree measures right Assume a directory tree where no sub-directories are symbolic links:: $ tree ./tests/listdir_nosymlinks ./tests/listdir_nosymlinks `-- depth1 `-- depth2 |-- 1024_byte_file `-- 10_byte_file 2 directories, 2 files And the files, ``tests/listdir_nosymlinks/depth1/depth2/10_byte_file`` and ``tests/listdir_nosymlinks/depth1/depth2/1024_byte_file`` are 10 Bytes and 1024 Bytes in size, respectively. Then: >>> for f in bitmath.listdir('./tests/listdir_nosymlinks'): ... print f Would yield 2-tuple's of: ('/path/tests/listdir_nosymlinks/depth1/depth2/10_byte_file', Byte(10.0)) ('/path/tests/listdir_nosymlinks/depth1/depth2/1024_byte_file', KiB(1.0)) """ # Call with relpath=True so the paths are easier to verify contents = list( bitmath.listdir('./tests/listdir_nosymlinks/', relpath=True)) # Ensure the returned paths match the expected paths discovered_paths = [ contents[0][0], contents[1][0], ] expected_paths = [ 'tests/listdir_nosymlinks/depth1/depth2/10_byte_file', 'tests/listdir_nosymlinks/depth1/depth2/1024_byte_file' ] self.assertListEqual(discovered_paths, expected_paths) expected_sizes = [bitmath.Byte(10.0), bitmath.Byte(1024.0)] discovered_sizes = [contents[0][1], contents[1][1]] self.assertListEqual(discovered_sizes, expected_sizes)
def test_listdir_filtering_nosymlinks(self): """listdir: no symbolic links in tree measures right with a filter Same assumptions as test_listdir_nosymlinks.""" # Call with relpath=True so the paths are easier to verify contents = list( bitmath.listdir( './tests/listdir_nosymlinks/', relpath=True, # Should only find 1 file, 1024_byte_file filter='1024*')) # Ensure the returned path matches the expected path self.assertEqual( contents[0][0], 'tests/listdir_nosymlinks/depth1/depth2/1024_byte_file') # Ensure the measured size is what we expect self.assertEqual(contents[0][1], bitmath.KiB(1.0))
def test_listdir_symlinks_follow_relpath_false(self): """listdir: symlinks followed, absolute paths are returned Same assumptions as in test_listdir_symlinks_follow. Difference is that the 0th item of the tuple returns a fully qualified path. """ contents = list( bitmath.listdir('./tests/listdir_symlinks/', followlinks=True)) # Ensure the returned path matches the expected path and # begins with the present working directory pwd = os.path.realpath('.') expected_paths = [ os.path.join(pwd, contents[0][0]), os.path.join(pwd, contents[1][0]) ] discovered_paths = [contents[0][0], contents[1][0]] self.assertListEqual(discovered_paths, expected_paths) # Ensure the measured size is what we expect expected_sizes = [bitmath.Byte(10.0), bitmath.Byte(10.0)] discovered_sizes = [contents[0][1], contents[1][1]] self.assertListEqual(discovered_sizes, expected_sizes)
def test_listdir_symlinks_follow(self): """listdir: symbolic links in tree are followed Same assumptions as in test_listdir_symlinks_nofollow. """ # Call with relpath=True so the paths are easier to verify contents = list( bitmath.listdir('./tests/listdir_symlinks/', followlinks=True, relpath=True)) # Ensure the returned path matches the expected path expected_paths = [ 'tests/listdir_symlinks/10_byte_file_link', 'tests/listdir_symlinks/depth1/depth2/10_byte_file' ] discovered_paths = [contents[0][0], contents[1][0]] self.assertListEqual(discovered_paths, expected_paths) # Ensure the measured size is what we expect expected_sizes = [bitmath.Byte(10.0), bitmath.Byte(10.0)] discovered_sizes = [contents[0][1], contents[1][1]] self.assertListEqual(discovered_sizes, expected_sizes)
def test_listdir_symlinks_nofollow(self): """listdir: symbolic links in tree not followed Similar assumptions as in test_listdir_nosymlinks, except the directory structure looks like this: $ tree tests/listdir_symlinks tests/listdir_symlinks |-- 10_byte_file_link -> ../listdir/10_byte_file `-- depth1 `-- depth2 `-- 10_byte_file 2 directories, 2 files """ # Call with relpath=True so the paths are easier to verify contents = list(bitmath.listdir('./tests/listdir_symlinks/', relpath=True)) # Ensure the returned path matches the expected path self.assertEqual(contents[0][0], 'tests/listdir_symlinks/depth1/depth2/10_byte_file') # Ensure the measured size is what we expect self.assertEqual(contents[0][1], bitmath.Byte(10.0))
if args.slowdown: # randomly slow down 1/5 of the time if random.randrange(0, 100) % 5 == 0: time.sleep(random.randrange(0, 500) * 0.01) # Nothing to see here. Go home. pbar.finish() ###################################################################### print(""" ###################################################################### List downloaded contents * Filter for .xz files only """) for p,bm in bitmath.listdir(DESTDIR, filter='*.xz'): print(p, bm) ###################################################################### print(""" ###################################################################### List downloaded contents * Filter for .gz files only * Print using best human readable prefix """) for p,bm in bitmath.listdir(DESTDIR, filter='*.gz', bestprefix=True): print(p, bm)