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
    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)
    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)
    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)
 def test_storages(self):
     res = [Host(0, "n"), Host(1, "n"), Storage(2, "n")]
     p = Platform(res)
     assert len(list(p.storages)) == 1
 def test_size(self):
     res = [Host(0, "n"), Host(1, "n"), Storage(2, "n")]
     p = Platform(res)
     assert p.size == len(res)
 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))
 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"
 def test_release_valid(self):
     s = Storage(0, "n")
     s._allocate("job")
     s._release("job")
     assert not s.jobs
 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
 def test_is_unavailable(self):
     m = {"n": 0}
     s = Storage(0, "0", True, m)
     s._set_unavailable()
     assert s.is_unavailable
    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
 def test_allocate_valid(self):
     s = Storage(0, "n")
     s._allocate("job")
     assert s.jobs and s.jobs[0] == "job"
 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
 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)
 def test_set_available(self):
     s = Storage(0, "0")
     s._set_unavailable()
     s._set_available()
     assert not s.is_unavailable
    def test_get_with_host(self):
        h1 = Host(0, "n")
        s1 = Storage(1, "n")
        p = Platform([h1, s1])

        assert p.get(0) == h1
 def test_str(self):
     s = str(Storage(0, "0", True))
     assert s == f"Storage_{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
 def test_metadata_optional(self):
     m = {"n": 0}
     s = Storage(0, "0", True)
     assert s.metadata == None
 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)
 def test_repr(self):
     assert repr(Storage(0, "0", True)) == f"Storage_{0}"