Skip to content

Commit

Permalink
#523: Fix CI after JSONValidator changes (#524)
Browse files Browse the repository at this point in the history
* #523: update JSON validator test with new args

* #523: add tests for new args

* #523: use different data for validating comm links
  • Loading branch information
cwschilly authored Aug 6, 2024
1 parent 5c66bb6 commit 6594331
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 15 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"type":"LBDatafile","phases":[{"id":0,"tasks":[{"entity":{"id":0,"home":0,"type":"object","migratable":true},"node":0,"resource":"cpu","time":1.0},{"entity":{"id":1,"home":0,"type":"object","migratable":true},"node":0,"resource":"cpu","time":0.5},{"entity":{"id":2,"home":0,"type":"object","migratable":true},"node":0,"resource":"cpu","time":0.5},{"entity":{"id":3,"home":0,"type":"object","migratable":true},"node":0,"resource":"cpu","time":0.5}],"communications":[{"type":"SendRecv","to":{"type":"object","id":5},"messages":1,"from":{"type":"object","id":0},"bytes":2.0},{"type":"SendRecv","to":{"type":"object","id":4},"messages":1,"from":{"type":"object","id":1},"bytes":1.0},{"type":"SendRecv","to":{"type":"object","id":2},"messages":1,"from":{"type":"object","id":3},"bytes":1.0},{"type":"SendRecv","to":{"type":"object","id":8},"messages":1,"from":{"type":"object","id":3},"bytes":0.5}]}]}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"type":"LBDatafile","phases":[{"id":0,"tasks":[{"entity":{"id":4,"home":1,"type":"object","migratable":true},"node":1,"resource":"cpu","time":0.5},{"entity":{"id":5,"home":1,"type":"object","migratable":true},"node":1,"resource":"cpu","time":2.0},{"entity":{"id":6,"home":1,"type":"object","migratable":true},"node":1,"resource":"cpu","time":1.0},{"entity":{"id":7,"home":1,"type":"object","migratable":true},"node":1,"resource":"cpu","time":0.5}],"communications":[{"type":"SendRecv","to":{"type":"object","id":1},"messages":1,"from":{"type":"object","id":4},"bytes":2.0},{"type":"SendRecv","to":{"type":"object","id":8},"messages":1,"from":{"type":"object","id":5},"bytes":2.0},{"type":"SendRecv","to":{"type":"object","id":6},"messages":1,"from":{"type":"object","id":7},"bytes":1.0}]}]}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"type":"LBDatafile","phases":[{"id":0,"tasks":[{"entity":{"id":8,"home":2,"type":"object","migratable":true},"node":2,"resource":"cpu","time":1.5}],"communications":[{"type":"SendRecv","to":{"type":"object","id":6},"messages":1,"from":{"type":"object","id":8},"bytes":1.5}]}]}
80 changes: 65 additions & 15 deletions tests/unit/imported/test_JSON_data_files_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ def setUp(self):
self.test_dir = os.path.dirname(os.path.dirname(__file__))
self.data_dir = os.path.join(self.test_dir, "data")
self.file_path = os.path.join(self.data_dir, "JSON_data_file_validator", "data.0.json")
self.comm_links_file_path = os.path.join(self.data_dir, "JSON_data_file_validator_comm_links", "data.0.json")
self.wrong_file_path = os.path.join(self.data_dir, "JSON_data_file_validator", "data.0.jso")
self.wrong_file_schema = os.path.join(self.data_dir, "JSON_data_file_validator_wrong", "data.0.json")
self.stats_file_001 = os.path.join(self.data_dir, "JSON_data_file_validator_stats", "vt_lb_statistics_001.json")
Expand All @@ -40,93 +41,117 @@ def test_json_data_files_validator_file(self):
argparse.ArgumentParser.parse_args.return_value = argparse.Namespace(file_path=self.file_path,
dir_path=None,
file_prefix=None,
file_suffix=None)
file_suffix=None,
validate_comm_links=False,
debug=False)
JSONDataFilesValidator().main()

def test_json_data_files_validator_dir(self):
argparse.ArgumentParser.parse_args = Mock()
argparse.ArgumentParser.parse_args.return_value = argparse.Namespace(file_path=None,
dir_path=self.dir_path,
file_prefix=None,
file_suffix=None)
file_suffix=None,
validate_comm_links=False,
debug=False)
JSONDataFilesValidator().main()

def test_json_data_files_validator_dir_compressed(self):
argparse.ArgumentParser.parse_args = Mock()
argparse.ArgumentParser.parse_args.return_value = argparse.Namespace(file_path=None,
dir_path=self.dir_path_compressed,
file_prefix=None,
file_suffix=None)
file_suffix=None,
validate_comm_links=False,
debug=False)
JSONDataFilesValidator().main()

def test_json_data_files_validator_file_stats_001(self):
argparse.ArgumentParser.parse_args = Mock()
argparse.ArgumentParser.parse_args.return_value = argparse.Namespace(file_path=self.stats_file_001,
dir_path=None,
file_prefix=None,
file_suffix=None)
file_suffix=None,
validate_comm_links=False,
debug=False)
JSONDataFilesValidator().main()

def test_json_data_files_validator_file_stats_002(self):
argparse.ArgumentParser.parse_args = Mock()
argparse.ArgumentParser.parse_args.return_value = argparse.Namespace(file_path=self.stats_file_002,
dir_path=None,
file_prefix=None,
file_suffix=None)
file_suffix=None,
validate_comm_links=False,
debug=False)
JSONDataFilesValidator().main()

def test_json_data_files_validator_file_stats_003(self):
argparse.ArgumentParser.parse_args = Mock()
argparse.ArgumentParser.parse_args.return_value = argparse.Namespace(file_path=self.stats_file_003,
dir_path=None,
file_prefix=None,
file_suffix=None)
file_suffix=None,
validate_comm_links=False,
debug=False)
JSONDataFilesValidator().main()

def test_json_data_files_validator_file_stats_004(self):
argparse.ArgumentParser.parse_args = Mock()
argparse.ArgumentParser.parse_args.return_value = argparse.Namespace(file_path=self.stats_file_004,
dir_path=None,
file_prefix=None,
file_suffix=None)
file_suffix=None,
validate_comm_links=False,
debug=False)
JSONDataFilesValidator().main()

def test_json_data_files_validator_file_stats_no_schema_type(self):
argparse.ArgumentParser.parse_args = Mock()
argparse.ArgumentParser.parse_args.return_value = argparse.Namespace(
file_path=self.vt_lb_statistics_no_schema_type, dir_path=None, file_prefix=None, file_suffix=None)
file_path=self.vt_lb_statistics_no_schema_type, dir_path=None, file_prefix=None, file_suffix=None,
validate_comm_links=False,
debug=False)
JSONDataFilesValidator().main()

def test_json_data_files_validator_prefix(self):
argparse.ArgumentParser.parse_args = Mock()
argparse.ArgumentParser.parse_args.return_value = argparse.Namespace(file_path=None,
dir_path=self.dir_path,
file_prefix="data",
file_suffix=None)
file_suffix=None,
validate_comm_links=False,
debug=False)
JSONDataFilesValidator().main()

def test_json_data_files_validator_suffix(self):
argparse.ArgumentParser.parse_args = Mock()
argparse.ArgumentParser.parse_args.return_value = argparse.Namespace(file_path=None,
dir_path=self.dir_path,
file_prefix=None,
file_suffix="json")
file_suffix="json",
validate_comm_links=False,
debug=False)
JSONDataFilesValidator().main()

def test_json_data_files_validator_prefix_suffix(self):
argparse.ArgumentParser.parse_args = Mock()
argparse.ArgumentParser.parse_args.return_value = argparse.Namespace(file_path=None,
dir_path=self.dir_path,
file_prefix="data",
file_suffix="json")
file_suffix="json",
validate_comm_links=False,
debug=False)
JSONDataFilesValidator().main()

def test_json_data_files_validator_file_not_found(self):
argparse.ArgumentParser.parse_args = Mock()
argparse.ArgumentParser.parse_args.return_value = argparse.Namespace(file_path=self.wrong_file_path,
dir_path=None,
file_prefix=None,
file_suffix=None)
file_suffix=None,
validate_comm_links=False,
debug=False)
with self.assertRaises(FileNotFoundError) as err:
JSONDataFilesValidator().main()
self.assertEqual(err.exception.args[0], f"File: {self.wrong_file_path} NOT found")
Expand All @@ -136,7 +161,9 @@ def test_json_data_files_validator_dir_not_found(self):
argparse.ArgumentParser.parse_args.return_value = argparse.Namespace(file_path=None,
dir_path=self.wrong_dir_path,
file_prefix=None,
file_suffix=None)
file_suffix=None,
validate_comm_links=False,
debug=False)
with self.assertRaises(FileNotFoundError) as err:
JSONDataFilesValidator().main()
self.assertEqual(err.exception.args[0], f"Directory: {self.wrong_dir_path} does NOT exist")
Expand All @@ -146,7 +173,9 @@ def test_json_data_files_validator_no_args(self):
argparse.ArgumentParser.parse_args.return_value = argparse.Namespace(file_path=None,
dir_path=None,
file_prefix=None,
file_suffix=None)
file_suffix=None,
validate_comm_links=False,
debug=False)
with self.assertRaises(Exception) as err:
JSONDataFilesValidator().main()
self.assertEqual(err.exception.args[0], "FILE path or DIRECTORY path has to be given")
Expand All @@ -156,13 +185,34 @@ def test_json_data_files_validator_wrong_file_schema(self):
argparse.ArgumentParser.parse_args.return_value = argparse.Namespace(file_path=self.wrong_file_schema,
dir_path=None,
file_prefix=None,
file_suffix=None)
file_suffix=None,
validate_comm_links=False,
debug=False)
with self.assertRaises(SchemaError) as err:
JSONDataFilesValidator().main()
with open(os.path.join(self.data_dir, "JSON_data_file_validator_wrong", "schema_error.txt"), "rt") as se:
err_msg = se.read()
self.assertEqual(err.exception.args[0], err_msg)

def test_json_data_files_validate_comm_links(self):
argparse.ArgumentParser.parse_args = Mock()
argparse.ArgumentParser.parse_args.return_value = argparse.Namespace(file_path=self.comm_links_file_path,
dir_path=None,
file_prefix=None,
file_suffix=None,
validate_comm_links=True,
debug=False)
JSONDataFilesValidator().main()

def test_json_data_files_debug(self):
argparse.ArgumentParser.parse_args = Mock()
argparse.ArgumentParser.parse_args.return_value = argparse.Namespace(file_path=self.file_path,
dir_path=None,
file_prefix=None,
file_suffix=None,
validate_comm_links=False,
debug=True)
JSONDataFilesValidator().main()

if __name__ == "__main__":
unittest.main()

0 comments on commit 6594331

Please sign in to comment.