Ejemplo n.º 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
Ejemplo n.º 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)
Ejemplo n.º 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)
Ejemplo n.º 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)
Ejemplo n.º 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
Ejemplo n.º 6
0
 def test_size(self):
     res = [Host(0, "n"), Host(1, "n"), Storage(2, "n")]
     p = Platform(res)
     assert p.size == len(res)
Ejemplo n.º 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))
Ejemplo n.º 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"
Ejemplo n.º 9
0
 def test_release_valid(self):
     s = Storage(0, "n")
     s._allocate("job")
     s._release("job")
     assert not s.jobs
Ejemplo n.º 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
Ejemplo n.º 11
0
 def test_is_unavailable(self):
     m = {"n": 0}
     s = Storage(0, "0", True, m)
     s._set_unavailable()
     assert s.is_unavailable
Ejemplo n.º 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
Ejemplo n.º 13
0
 def test_allocate_valid(self):
     s = Storage(0, "n")
     s._allocate("job")
     assert s.jobs and s.jobs[0] == "job"
Ejemplo n.º 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
Ejemplo n.º 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)
Ejemplo n.º 16
0
 def test_set_available(self):
     s = Storage(0, "0")
     s._set_unavailable()
     s._set_available()
     assert not s.is_unavailable
Ejemplo n.º 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
Ejemplo n.º 18
0
 def test_str(self):
     s = str(Storage(0, "0", True))
     assert s == f"Storage_{0}"
Ejemplo n.º 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
Ejemplo n.º 20
0
 def test_metadata_optional(self):
     m = {"n": 0}
     s = Storage(0, "0", True)
     assert s.metadata == None
Ejemplo n.º 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)
Ejemplo n.º 22
0
 def test_repr(self):
     assert repr(Storage(0, "0", True)) == f"Storage_{0}"