def test_list_returns_str(self): params = ["-q queue", "-P project"] actual = Config.concatenate_params(params) expected = "-q queue -P project" assert actual == expected
def test_args_to_dict(): args = '-W 0:01 -W 0:02 -J "test name"' actual = Config.args_to_dict(args) expected = {"-W": "0:02", "-J": "test name"} assert actual == expected
def test_str_returns_str(self): params = "-q queue" actual = Config.concatenate_params(params) expected = params assert actual == expected
def test_empty_list_returns_empty_str(self): params = [] actual = Config.concatenate_params(params) expected = "" assert actual == expected
def test_default_present_params_are_list_returns_params(self): stream = StringIO("__default__:\n - '-q foo'\n - '-P project'") config = Config.from_stream(stream) actual = config.default_params() expected = "-q foo -P project" assert actual == expected
def test_default_present_returns_params(self): stream = StringIO("__default__: '-q foo'") config = Config.from_stream(stream) actual = config.default_params() expected = "-q foo" assert actual == expected
def test_no_default_returns_empty(self): stream = StringIO("key: 'foo'") config = Config.from_stream(stream) actual = config.default_params() expected = "" assert actual == expected
def test_get_empty_returns_default(self): stream = StringIO("") config = Config.from_stream(stream) key = "key" actual = config.get(key) assert actual is None
def test_default_present_without_underscores_returns_empty(self): stream = StringIO("default:\n - '-q foo'\n - '-P project'") config = Config.from_stream(stream) actual = config.default_params() expected = "" assert actual == expected
def test_rule_present_but_not_default_returns_rule_params(self): stream = StringIO("rule:\n - '-P project'\n - '-q bar'") config = Config.from_stream(stream) rulename = "rule" actual = config.params_for_rule(rulename) expected = "-P project -q bar" assert actual == expected
def test_get_key_in_yaml(self): stream = StringIO("key: 'foo'") key = "key" config = Config.from_stream(stream) actual = config.get(key) expected = "foo" assert actual == expected
def test_rule_and_default_present_returns_default_and_rule_params(self): stream = StringIO("__default__: '-q foo'\nrule:\n - '-P project'\n") config = Config.from_stream(stream) rulename = "rule" actual = config.params_for_rule(rulename) expected = "-q foo -P project" assert actual == expected
def test_default_present_but_not_rule_returns_default_params(self): stream = StringIO("__default__: '-q foo'") config = Config.from_stream(stream) rulename = "a" actual = config.params_for_rule(rulename) expected = "-q foo" assert actual == expected
def test_no_default_or_rule_returns_empty(self): stream = StringIO("key: 'foo'") config = Config.from_stream(stream) rulename = "a" actual = config.params_for_rule(rulename) expected = "" assert actual == expected
def test_get_key_not_in_yaml_returns_default(self): stream = StringIO("key: 'foo'") key = "bar" default = "default" config = Config.from_stream(stream) actual = config.get(key, default) expected = default assert actual == expected
def test_rule_and_default_have_same_params_rule_params_take_precedent( self): stream = StringIO( "__default__: '-q foo'\nrule:\n - '-P project'\n - '-q bar'") config = Config.from_stream(stream) rulename = "rule" actual = config.params_for_rule(rulename) expected = "-q bar -P project" assert actual == expected
def test_resource_requirements_two_levels_of_quoting(self): config_string = """ __default__: - "-R \\"select[hname!='escaped-hostname']\\"" """ stream = StringIO(config_string) config = Config.from_stream(stream) actual = config.params_for_rule("rule") expected = "-R 'select[hname!='\"'\"'escaped-hostname'\"'\"']'" assert actual == expected
def test_resource_requirements_one_level_of_quoting(self): config_string = """ __default__: - "-R 'select[mem>2000] rusage[mem=2000]'" """ stream = StringIO(config_string) config = Config.from_stream(stream) actual = config.params_for_rule("rule") expected = "-R 'select[mem>2000] rusage[mem=2000]'" assert actual == expected
def test_rule_specific_params_are_submitted(self, *mocks): argv = [ "script_name", "cluster_opt_1", "cluster_opt_2", "cluster_opt_3", "real_jobscript.sh", ] content = """ __default__: - "-R 'select[mem>2000]'" - '-gpu -' search_fasta_on_index: '-P project' """ stream = StringIO(content) lsf_config = Config.from_stream(stream) memory_units = Unit.MEGA jobscript = argv[-1] cluster_cmds = argv[1:-1] lsf_submit = Submitter( jobscript=jobscript, cluster_cmds=cluster_cmds, memory_units=memory_units, lsf_config=lsf_config, ) actual = lsf_submit.submit_cmd expected_mem = "2662" expected_outlog = ( Path("logdir") / "search_fasta_on_index" / "i=0" / "jobid2_random.out" ) expected_errlog = ( Path("logdir") / "search_fasta_on_index" / "i=0" / "jobid2_random.err" ) expected_jobinfo_cmd = ( '-o "{outlog}" -e "{errlog}" -J "search_fasta_on_index.i=0"' ).format(outlog=expected_outlog, errlog=expected_errlog) expected = ( "bsub -M {mem} -n 1 -R 'select[mem>{mem}] rusage[mem={mem}] span[hosts=1]' " "{jobinfo} -q q1 cluster_opt_1 cluster_opt_2 cluster_opt_3 " "-R 'select[mem>2000]' -gpu - -P project " "real_jobscript.sh".format(mem=expected_mem, jobinfo=expected_jobinfo_cmd) ) assert actual == expected
def test_lsf_mem_unit_is_tb_and_mem_mb_is_converted_and_rounded_up_to_int( self, *mocks ): argv = [ "script_name", "cluster_opt_1", "cluster_opt_2", "cluster_opt_3", "real_jobscript.sh", ] content = ( "__default__:\n - '-q queue'\n - '-gpu -'\n" "search_fasta_on_index: '-P project'" ) stream = StringIO(content) lsf_config = Config.from_stream(stream) lsf_mem_unit = Unit.TERA jobscript = argv[-1] cluster_cmds = argv[1:-1] lsf_submit = Submitter( jobscript=jobscript, cluster_cmds=cluster_cmds, memory_units=lsf_mem_unit, lsf_config=lsf_config, ) actual = lsf_submit.submit_cmd expected_mem = "1" expected_outlog = ( Path("logdir") / "search_fasta_on_index" / "i=0" / "jobid2_random.out" ) expected_errlog = ( Path("logdir") / "search_fasta_on_index" / "i=0" / "jobid2_random.err" ) expected_jobinfo_cmd = ( '-o "{outlog}" -e "{errlog}" -J "search_fasta_on_index.i=0"' ).format(outlog=expected_outlog, errlog=expected_errlog) expected = ( "bsub -M {mem} -n 1 -R 'select[mem>{mem}] rusage[mem={mem}] span[hosts=1]' " "{jobinfo} -q q1 cluster_opt_1 cluster_opt_2 cluster_opt_3 " "-q queue -gpu - -P project " "real_jobscript.sh".format(mem=expected_mem, jobinfo=expected_jobinfo_cmd) ) assert actual == expected
def test_no_options_given_returns_empty(self): config = Config() assert not config
def test_non_empty_returns_true(self): config = Config({1: 1}) assert config
def test_item_in_config(self): stream = StringIO("key: 'foo'") item = "key" config = Config.from_stream(stream) assert item in config
def test_empty_returns_false(self): config = Config({}) assert not config
def test_only_keys_are_tested_for_membership(self): stream = StringIO("key: 'foo'") item = "foo" config = Config.from_stream(stream) assert item not in config