tests: Improve Resource Downloader Test Suite
Theses improvements are: 1. Renames the test suite to the correct "ResourceDownloaderTestSuite". This was correctly named MD5FileTestSuite due to a copy-and-paste error. 2. Adds the `setUpClass` and `tearDownClass` from the Python's unittest framework. These are used to create the simple "resources.json" file used for testing, set the "GEM5_RESOURCE_JSON", and delete these when the test is complete. 3. The tests have been updated to utilize the improvements added in 2. Change-Id: Ia54e45892452bf23b54c8b5a6bb4a94910d83c5f Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/62651 Reviewed-by: Jason Lowe-Power <power.jg@gmail.com> Maintainer: Jason Lowe-Power <power.jg@gmail.com> Tested-by: kokoro <noreply+kokoro@google.com>
This commit is contained in:
committed by
Bobby Bruce
parent
329a917c71
commit
86a8da1a32
@@ -36,10 +36,11 @@ from gem5.resources.downloader import (
|
||||
)
|
||||
|
||||
|
||||
class MD5FileTestSuite(unittest.TestCase):
|
||||
class ResourceDownloaderTestSuite(unittest.TestCase):
|
||||
"""Test cases for gem5.resources.downloader"""
|
||||
|
||||
def create_temp_resources_json(self) -> str:
|
||||
@classmethod
|
||||
def setUpClass(cls) -> str:
|
||||
"""
|
||||
This creates a simple resource.json temp file for testing purposes.
|
||||
"""
|
||||
@@ -84,7 +85,14 @@ class MD5FileTestSuite(unittest.TestCase):
|
||||
file = tempfile.NamedTemporaryFile(mode="w", delete=False)
|
||||
file.write(file_contents)
|
||||
file.close()
|
||||
return file.name
|
||||
cls.file_path = file.name
|
||||
|
||||
os.environ["GEM5_RESOURCE_JSON"] = cls.file_path
|
||||
|
||||
@classmethod
|
||||
def tearDownClass(cls) -> None:
|
||||
os.remove(cls.file_path)
|
||||
del os.environ["GEM5_RESOURCE_JSON"]
|
||||
|
||||
def verify_json(self, json: Dict) -> None:
|
||||
"""
|
||||
@@ -105,28 +113,15 @@ class MD5FileTestSuite(unittest.TestCase):
|
||||
# Tests the gem5.resources.downloader._get_resources_json_at_path()
|
||||
# function.
|
||||
|
||||
path = self.create_temp_resources_json()
|
||||
json = _get_resources_json_at_path(path=path)
|
||||
|
||||
json = _get_resources_json_at_path(path=self.file_path)
|
||||
self.verify_json(json=json)
|
||||
|
||||
# Cleanup the temp file
|
||||
os.remove(path)
|
||||
|
||||
def test_get_resources_json(self) -> None:
|
||||
# Tests the gem5.resources.downloader._get_resources_json() function.
|
||||
|
||||
path = self.create_temp_resources_json()
|
||||
|
||||
# We set the "GEM5_RESOURCE_JSON" environment variable to allow using
|
||||
# our test temp resources.json.
|
||||
os.environ["GEM5_RESOURCE_JSON"] = path
|
||||
json = _get_resources_json()
|
||||
self.verify_json(json=json)
|
||||
|
||||
# Cleanup the temp file
|
||||
os.remove(path)
|
||||
|
||||
def test_get_resources_json_invalid_url(self) -> None:
|
||||
# Tests the gem5.resources.downloader._get_resources_json() function in
|
||||
# case where an invalid url is passed as the URL/PATH of the
|
||||
@@ -141,3 +136,6 @@ class MD5FileTestSuite(unittest.TestCase):
|
||||
f"Resources location '{path}' is not a valid path or URL."
|
||||
in str(context.exception)
|
||||
)
|
||||
|
||||
# Set back to the old path
|
||||
os.environ["GEM5_RESOURCE_JSON"] = self.file_path
|
||||
|
||||
Reference in New Issue
Block a user