示例#1
0
 def test_valid(self):
     m = {"n": 0}
     s = Storage(0, "0", True, m)
     assert s.id == 0
     assert s.name == "0"
     assert s.metadata == m
     assert not s.is_unavailable
示例#2
0
    def test_get_not_found_must_raise(self):
        h1 = Host(0, "n")
        s1 = Storage(1, "n")
        p = Platform([h1, s1])
        with pytest.raises(LookupError) as excinfo:
            p.get(2)

        assert "no resources" in str(excinfo.value)
示例#3
0
    def test_get_storage_with_host_id_must_raise(self):
        h1 = Host(0, "n")
        s1 = Storage(1, "n")
        p = Platform([h1, s1])

        with pytest.raises(LookupError) as excinfo:
            p.get_storage(0)

        assert "storage" in str(excinfo.value)
示例#4
0
    def test_allocate_when_unavailable_must_raise(self):
        m = {"n": 0}
        s = Storage(0, "0", True, m)
        s._set_unavailable()
        with pytest.raises(RuntimeError) as excinfo:
            s._allocate("job")

        assert "unavailable" in str(excinfo.value)
示例#5
0
 def test_storages(self):
     res = [Host(0, "n"), Host(1, "n"), Storage(2, "n")]
     p = Platform(res)
     assert len(list(p.storages)) == 1
示例#6
0
 def test_size(self):
     res = [Host(0, "n"), Host(1, "n"), Storage(2, "n")]
     p = Platform(res)
     assert p.size == len(res)
示例#7
0
 def test_valid_instance(self):
     res = [Host(0, "n"), Host(1, "n"), Storage(2, "n")]
     p = Platform(res)
     assert all(h.id == i for i, h in enumerate(p.resources))
示例#8
0
 def test_release_when_multiple_jobs_are_allocated(self):
     s = Storage(0, "n")
     s._allocate("j1")
     s._allocate("j2")
     s._release("j1")
     assert s.jobs and len(s.jobs) == 1 and s.jobs[0] == "j2"
示例#9
0
 def test_release_valid(self):
     s = Storage(0, "n")
     s._allocate("job")
     s._release("job")
     assert not s.jobs
示例#10
0
 def test_allocate_job_twice_must_not_raise(self):
     s = Storage(0, "n")
     s._allocate("j1")
     s._allocate("j1")
     assert s.jobs and len(s.jobs) == 1
示例#11
0
 def test_is_unavailable(self):
     m = {"n": 0}
     s = Storage(0, "0", True, m)
     s._set_unavailable()
     assert s.is_unavailable
示例#12
0
    def test_get_storage_by_id(self):
        h1 = Host(0, "n")
        s1 = Storage(1, "n")
        p = Platform([h1, s1])

        assert p.get_storage(1) == s1
示例#13
0
 def test_allocate_valid(self):
     s = Storage(0, "n")
     s._allocate("job")
     assert s.jobs and s.jobs[0] == "job"
示例#14
0
 def test_set_unavailable_when_already_allocated_must_not_raise(self):
     m = {"n": 0}
     s = Storage(0, "0", True, m)
     s._allocate("job")
     s._set_unavailable()
     assert s.is_unavailable and s.jobs
示例#15
0
 def test_set_available_without_being_unavailable_must_raise(self):
     m = {"n": 0}
     s = Storage(0, "0", True, m)
     with pytest.raises(SystemError) as excinfo:
         s._set_available()
     assert "unavailable" in str(excinfo.value)
示例#16
0
 def test_set_available(self):
     s = Storage(0, "0")
     s._set_unavailable()
     s._set_available()
     assert not s.is_unavailable
示例#17
0
    def test_get_with_host(self):
        h1 = Host(0, "n")
        s1 = Storage(1, "n")
        p = Platform([h1, s1])

        assert p.get(0) == h1
示例#18
0
 def test_str(self):
     s = str(Storage(0, "0", True))
     assert s == f"Storage_{0}"
示例#19
0
 def test_allocate_multiple_jobs_valid(self):
     s = Storage(0, "n")
     s._allocate("j1")
     s._allocate("j2")
     assert "j1" in s.jobs
     assert "j2" in s.jobs
示例#20
0
 def test_metadata_optional(self):
     m = {"n": 0}
     s = Storage(0, "0", True)
     assert s.metadata == None
示例#21
0
 def test_allocate_multiple_jobs_when_not_shareable_must_raise(self):
     s = Storage(0, "n", False)
     s._allocate("j1")
     with pytest.raises(RuntimeError) as excinfo:
         s._allocate("j2")
     assert "multiple jobs" in str(excinfo.value)
示例#22
0
 def test_repr(self):
     assert repr(Storage(0, "0", True)) == f"Storage_{0}"