def test_multiple_spaces_between_size_and_suffix_is_valid(self):
        s = "500  MB"

        actual = Memory.from_str(s)
        expected = Memory(500, Unit.MEGA)

        assert actual == expected
    def test_suffix_is_case_insensitive(self):
        s = "500zb"

        actual = Memory.from_str(s).bytes()
        expected = Memory(500, Unit.ZETTA).bytes()

        assert actual == expected
    def test_same_value_and_unit(self):
        value = 50
        unit = Unit.PETA
        mem1 = Memory(value, unit)
        mem2 = Memory(value, unit)

        assert mem1 == mem2
    def test_no_suffix_returns_bytes(self):
        s = "500"

        actual = Memory.from_str(s)
        expected = Memory(500)

        assert actual == expected
    def test_bytes_suffix_is_valid(self):
        s = "7B"

        actual = Memory.from_str(s)
        expected = Memory(7)

        assert actual == expected
    def test_no_suffix_and_float_returns_bytes(self):
        s = "500.8"

        actual = Memory.from_str(s)
        expected = Memory(500.8)

        assert actual == expected
    def test_b_suffix_is_valid(self):
        s = "500MB"

        actual = Memory.from_str(s)
        expected = Memory(500, Unit.MEGA)

        assert actual == expected
    def test_terabytes_to_megabytes(self):
        memory = Memory(30, Unit.TERA)
        desired_units = Unit.MEGA

        actual = memory.to(desired_units)
        expected = Memory(30000000, desired_units)

        assert actual == expected
    def test_bytes_to_megabytes(self):
        memory = Memory(2500)
        desired_units = Unit.MEGA

        actual = memory.to(desired_units)
        expected = Memory(0.0025, desired_units)

        assert actual == expected
    def test_bytes_to_kilobytes(self):
        memory = Memory(10)
        desired_units = Unit.KILO

        actual = memory.to(desired_units)
        expected = Memory(0.01, desired_units)

        assert actual == expected
    def test_different_value_same_unit(self):
        value1 = 50
        unit = Unit.PETA
        mem1 = Memory(value1, unit)
        value2 = 60
        mem2 = Memory(value2, unit)

        assert mem1 != mem2
    def test_same_value_different_unit(self):
        value = 50
        unit1 = Unit.PETA
        mem1 = Memory(value, unit1)
        unit2 = Unit.KILO
        mem2 = Memory(value, unit2)

        assert mem1 != mem2
    def test_memory_is_bytes_no_conversion_needed(self):
        value = 40
        mem = Memory(value)

        actual = mem.bytes()
        expected = value

        assert actual == expected
    def test_terabytes_to_kilobytes_in_binary(self):
        memory = Memory(30, Unit.TERA)
        desired_units = Unit.KILO

        actual = memory.to(desired_units, decimal_multiples=False)
        expected = Memory(32212254720, desired_units)

        assert actual == expected
    def test_bytes_to_bytes(self):
        memory = Memory(10)
        desired_units = Unit.BYTES

        actual = memory.to(desired_units)
        expected = Memory(10, desired_units)

        assert actual == expected
    def test_kilobytes_to_gigabytes(self):
        memory = Memory(2500, Unit.KILO)
        desired_units = Unit.GIGA

        actual = memory.to(desired_units)
        expected = Memory(0.0025, desired_units)

        assert actual == expected
    def test_memory_is_megabytes_conversion_needed(self):
        value = 40
        unit = Unit.MEGA
        mem = Memory(value, unit)

        actual = mem.bytes()
        expected = 40000000

        assert actual == expected
    def test_large_floats_comparison(self):
        value = 500
        unit = Unit.ZETTA
        mem = Memory(value, unit)

        actual = mem.bytes()
        expected = float(500000000000000000000000)

        assert actual == expected
    def test_float_as_value(self):
        value = 0.5
        unit = Unit.GIGA
        mem = Memory(value, unit)

        actual = mem.bytes()
        expected = 500000000

        assert actual == expected
    def test_memory_is_kilobytes_nondecimal_returns_power_of_two(self):
        value = 40
        unit = Unit.KILO
        mem = Memory(value, unit)

        actual = mem.bytes(decimal_multiples=False)
        expected = 40960

        assert actual == expected
def test_memory_suffix():
    mem = Memory(3, Unit.EXA)

    actual = mem.suffix
    expected = "EB"

    assert actual == expected
    def test_float_number_returns_float(self):
        memory = Memory(50.2, Unit.ZETTA)

        actual = str(memory)
        expected = "50.2ZB"

        assert actual == expected
    def test_round_float_number_returns_int(self):
        memory = Memory(50.0, Unit.KILO)

        actual = str(memory)
        expected = "50KB"

        assert actual == expected
def test_memory_power():
    mem = Memory(3, Unit.MEGA)

    actual = mem.power
    expected = 2

    assert actual == expected
 def test___several_trivial_getter_methods(self, *mocks):
     argv = [
         "script_name",
         "cluster_opt_1",
         "cluster_opt_2",
         "cluster_opt_3",
         "real_jobscript.sh",
     ]
     memory_units = Unit.KILO
     memory_mb_value = 2662
     jobscript = argv[-1]
     cluster_cmds = argv[1:-1]
     lsf_submit = Submitter(jobscript=jobscript,
                            cluster_cmds=cluster_cmds,
                            memory_units=memory_units)
     self.assertEqual(lsf_submit.jobscript, "real_jobscript.sh")
     self.assertEqual(lsf_submit.cluster_cmd,
                      "cluster_opt_1 cluster_opt_2 cluster_opt_3")
     self.assertEqual(lsf_submit.threads, 1)
     self.assertEqual(lsf_submit.mem_mb, Memory(memory_mb_value, Unit.MEGA))
     self.assertEqual(lsf_submit.jobid, "2")
     expected_wildcards_str = "i=0"
     self.assertEqual(lsf_submit.wildcards_str, expected_wildcards_str)
     expected_rule_name = "search_fasta_on_index"
     self.assertEqual(lsf_submit.rule_name, expected_rule_name)
     self.assertEqual(lsf_submit.is_group_jobtype, False)
     expected_mem = "{}000".format(memory_mb_value)
     expected_resource_cmd = (
         "-M {mem} -n 1 -R 'select[mem>{mem}] rusage[mem={mem}] span[hosts=1]'"
     ).format(mem=expected_mem)
     self.assertEqual(
         lsf_submit.resources_cmd,
         expected_resource_cmd,
     )
     self.assertEqual(lsf_submit.jobname, "search_fasta_on_index.i=0")
     expected_logdir = Path(
         "logdir") / expected_rule_name / expected_wildcards_str
     self.assertEqual(lsf_submit.logdir, expected_logdir)
     expected_outlog = expected_logdir / "jobid2_random.out"
     self.assertEqual(lsf_submit.outlog, expected_outlog)
     expected_errlog = expected_logdir / "jobid2_random.err"
     self.assertEqual(lsf_submit.errlog, expected_errlog)
     expected_jobinfo_cmd = (
         '-o "{outlog}" -e "{errlog}" -J "search_fasta_on_index.i=0"'
     ).format(outlog=expected_outlog, errlog=expected_errlog)
     self.assertEqual(
         lsf_submit.jobinfo_cmd,
         expected_jobinfo_cmd,
     )
     self.assertEqual(lsf_submit.queue_cmd, "-q q1")
     self.assertEqual(
         lsf_submit.submit_cmd,
         "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 "
         "real_jobscript.sh".format(mem=expected_mem,
                                    jobinfo=expected_jobinfo_cmd),
     )
    def test_empty_string_raises_error(self):
        s = ""

        with pytest.raises(InvalidMemoryString):
            Memory.from_str(s)
    def test_different_value_different_unit_different_bytes(self):
        mem1 = Memory(500, Unit.KILO)
        mem2 = Memory(0.5, Unit.GIGA)

        assert mem1 != mem2
    def test_invalid_suffix_raises_error(self):
        s = "7LB"

        with pytest.raises(InvalidMemoryString):
            Memory.from_str(s)
    def test_suffix_only_raises_error(self):
        s = "TB"

        with pytest.raises(InvalidMemoryString):
            Memory.from_str(s)
    def test_string_with_other_characters_raises_error(self):
        s = "7KBY"

        with pytest.raises(InvalidMemoryString):
            Memory.from_str(s)