Exemplo n.º 1
0
    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
Exemplo n.º 2
0
    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
Exemplo n.º 3
0
    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
Exemplo n.º 4
0
    def test_no_default_returns_empty(self):
        stream = StringIO("key: 'foo'")
        config = Config.from_stream(stream)

        actual = config.default_params()
        expected = ""

        assert actual == expected
Exemplo n.º 5
0
    def test_get_empty_returns_default(self):
        stream = StringIO("")
        config = Config.from_stream(stream)
        key = "key"

        actual = config.get(key)

        assert actual is None
Exemplo n.º 6
0
    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
Exemplo n.º 7
0
    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
Exemplo n.º 8
0
    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
Exemplo n.º 9
0
    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
Exemplo n.º 10
0
    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
Exemplo n.º 11
0
    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
Exemplo n.º 12
0
    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
Exemplo n.º 13
0
    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
Exemplo n.º 14
0
    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
Exemplo n.º 15
0
    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
Exemplo n.º 16
0
    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
Exemplo n.º 17
0
    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
Exemplo n.º 18
0
    def test_item_in_config(self):
        stream = StringIO("key: 'foo'")
        item = "key"
        config = Config.from_stream(stream)

        assert item in config