1import json
2import pytest
3import uuid
4
5
6def test_register_job(nomad_setup):
7
8    with open("example.json") as fh:
9        job = json.loads(fh.read())
10        nomad_setup.job.register_job("example", job)
11        assert "example" in nomad_setup.job
12
13
14# integration tests requires nomad Vagrant VM or Binary running
15def test_get_evaluation(nomad_setup):
16    evalID = nomad_setup.job.get_allocations("example")[0]["EvalID"]
17    assert isinstance(
18        nomad_setup.evaluation.get_evaluation(evalID), dict) == True
19
20
21def test_get_allocations(nomad_setup):
22    evalID = nomad_setup.job.get_allocations("example")[0]["EvalID"]
23    e = nomad_setup.evaluation[evalID]
24    a = nomad_setup.evaluation.get_allocations(evalID)
25    assert len(a) >= 0
26
27
28def test_dunder_getitem_exist(nomad_setup):
29    evalID = nomad_setup.job.get_allocations("example")[0]["EvalID"]
30    e = nomad_setup.evaluation[evalID]
31    assert isinstance(e, dict)
32
33
34def test_dunder_getitem_not_exist(nomad_setup):
35
36    with pytest.raises(KeyError):
37        _ = nomad_setup.evaluation[str(uuid.uuid4())]
38
39
40def test_dunder_contain_exists(nomad_setup):
41    evalID = nomad_setup.job.get_allocations("example")[0]["EvalID"]
42    assert evalID in nomad_setup.evaluation
43
44
45def test_dunder_contain_not_exist(nomad_setup):
46    assert str(uuid.uuid4()) not in nomad_setup.evaluation
47
48
49def test_dunder_str(nomad_setup):
50    assert isinstance(str(nomad_setup.evaluation), str)
51
52
53def test_dunder_repr(nomad_setup):
54    assert isinstance(repr(nomad_setup.evaluation), str)
55
56
57def test_dunder_getattr(nomad_setup):
58
59    with pytest.raises(AttributeError):
60        _ = nomad_setup.evaluation.does_not_exist
61