def check_space_for_hashtable(args, hashtype, force, _testhook_free_space=None): """Check we have enough size to write a hash table.""" hash_size = khmer_args._calculate_tablesize(args, hashtype) cwd = os.getcwd() dir_path = os.path.dirname(os.path.realpath(cwd)) target = os.statvfs(dir_path) if _testhook_free_space is None: free_space = target.f_frsize * target.f_bavail else: free_space = _testhook_free_space # allow us to test this code... size_diff = hash_size - free_space if size_diff > 0: print("ERROR: Not enough free space on disk " "for saved table files;" " Need at least %s GB more." % (float(size_diff) / 1e9,), file=sys.stderr) print(" Table size: %.1f GB" % (float(hash_size) / 1e9,), file=sys.stderr) print(" Free space: %.1f GB" % (float(free_space) / 1e9,), file=sys.stderr) if not force: sys.exit(1)
def test_fail_calculate_foograph_size(): # tests unknown graph type ksize = khmer_args.DEFAULT_K n_tables = khmer_args.DEFAULT_N_TABLES max_tablesize = khmer_args.DEFAULT_MAX_TABLESIZE max_mem = 1e7 args = FakeArgparseObject(ksize, n_tables, max_tablesize, max_mem) try: nodegraph = khmer_args._calculate_tablesize(args, 'foograph') assert 0, "previous statement should fail" except AssertionError: raise except Exception as err: assert "unknown graph type: foograph" in str(err), str(err)