2022-12-04 10:05:31 +01:00
|
|
|
import unittest
|
2022-12-06 14:55:58 +01:00
|
|
|
import os
|
2022-12-04 10:05:31 +01:00
|
|
|
|
2022-12-06 14:55:58 +01:00
|
|
|
from nixglhost_wrapper import CacheDirContent, LibraryPath, ResolvedLib
|
2022-12-04 10:05:31 +01:00
|
|
|
|
|
|
|
|
|
|
|
class TestCacheSerializer(unittest.TestCase):
|
2022-12-06 14:55:58 +01:00
|
|
|
def test_hostdso_json_golden_test(self):
|
|
|
|
lp = LibraryPath(
|
|
|
|
glx=[
|
|
|
|
ResolvedLib(
|
2022-12-04 10:05:31 +01:00
|
|
|
"dummyglx.so",
|
2022-12-06 14:55:58 +01:00
|
|
|
"/lib",
|
2022-12-04 10:05:31 +01:00
|
|
|
"/lib/dummyglx.so",
|
|
|
|
"031edd7d41651593c5fe5c006fa5752b37fddff7bc4e843aa6af0c950f4b9406",
|
|
|
|
)
|
2022-12-06 14:55:58 +01:00
|
|
|
],
|
|
|
|
cuda=[
|
|
|
|
ResolvedLib(
|
2022-12-04 10:05:31 +01:00
|
|
|
"dummycuda.so",
|
2022-12-06 14:55:58 +01:00
|
|
|
"/lib",
|
2022-12-04 10:05:31 +01:00
|
|
|
"/lib/dummycuda.so",
|
|
|
|
"031edd7d41651593c5fe5c006fa5752b37fddff7bc4e843aa6af0c950f4b9407",
|
|
|
|
)
|
2022-12-06 14:55:58 +01:00
|
|
|
],
|
|
|
|
generic=[
|
|
|
|
ResolvedLib(
|
2022-12-04 10:05:31 +01:00
|
|
|
"dummygeneric.so",
|
2022-12-06 14:55:58 +01:00
|
|
|
"/lib",
|
2022-12-04 10:05:31 +01:00
|
|
|
"/lib/dummygeneric.so",
|
|
|
|
"031edd7d41651593c5fe5c006fa5752b37fddff7bc4e843aa6af0c950f4b9408",
|
|
|
|
)
|
2022-12-06 14:55:58 +01:00
|
|
|
],
|
|
|
|
egl=[
|
|
|
|
ResolvedLib(
|
|
|
|
"dummyegl.so",
|
|
|
|
"/lib",
|
|
|
|
"/lib/dummyegl.so",
|
|
|
|
"031edd7d41651593c5fe5c006fa5752b37fddff7bc4e843aa6af0c950f4b9409",
|
|
|
|
)
|
|
|
|
],
|
|
|
|
path="/path/to/lib/dir",
|
2022-12-04 10:05:31 +01:00
|
|
|
)
|
2022-12-06 14:55:58 +01:00
|
|
|
cdc = CacheDirContent([lp])
|
|
|
|
json = cdc.to_json()
|
|
|
|
|
|
|
|
self.assertIsNotNone(json)
|
|
|
|
golden_cdc = CacheDirContent.from_json(json)
|
|
|
|
self.assertEqual(cdc, golden_cdc)
|
|
|
|
self.assertEqual(cdc.to_json(), golden_cdc.to_json())
|
2022-12-04 10:05:31 +01:00
|
|
|
|
|
|
|
def test_eq_commut_jsons(self):
|
|
|
|
"""Checks that object equality is not sensible to JSON keys commutations"""
|
2022-12-06 14:55:58 +01:00
|
|
|
cwd = os.path.dirname(os.path.realpath(__file__))
|
|
|
|
with open(
|
|
|
|
os.path.join(cwd, "..", "tests", "fixtures", "json_permut", "1.json"),
|
|
|
|
"r",
|
|
|
|
encoding="utf8",
|
|
|
|
) as f:
|
|
|
|
cdc_json = f.read()
|
|
|
|
with open(
|
|
|
|
os.path.join(cwd, "..", "tests", "fixtures", "json_permut", "2.json"),
|
|
|
|
"r",
|
|
|
|
encoding="utf8",
|
|
|
|
) as f:
|
|
|
|
commut_cdc_json = f.read()
|
|
|
|
with open(
|
|
|
|
os.path.join(
|
|
|
|
cwd, "..", "tests", "fixtures", "json_permut", "not-equal.json"
|
|
|
|
),
|
|
|
|
"r",
|
|
|
|
encoding="utf8",
|
|
|
|
) as f:
|
|
|
|
wrong_cdc_json = f.read()
|
|
|
|
cdc = CacheDirContent.from_json(cdc_json)
|
|
|
|
commut_cdc = CacheDirContent.from_json(commut_cdc_json)
|
|
|
|
wrong_cdc = CacheDirContent.from_json(wrong_cdc_json)
|
|
|
|
self.assertEqual(cdc, commut_cdc)
|
|
|
|
self.assertNotEqual(cdc, wrong_cdc)
|
|
|
|
self.assertNotEqual(commut_cdc, wrong_cdc)
|
2022-12-04 10:05:31 +01:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
unittest.main()
|