Skip to content

Commit 071622c

Browse files
committed
Using decorators for comprehensive testing
Jussi in his comment here: #1391 (comment) proposed using decorators when creating comprehensive testing for metadata serialization. The main problems he pointed out is that: 1) there is a lot of code needed to generate the data for each case 2) the test implementation scales badly when you want to add new cases for your tests, then you would have to add code as well 3) the dictionary format is not visible - we are loading external files and assuming they are not changed and valid In this change, I am using a decorator with an argument that complicates the implementation of the decorator and requires three nested functions, but the advantages are that we are resolving the above three problems: 1) we don't need new code when adding a new test case 2) a small amount of hardcoded data is required for each new test 3) the dictionaries are all in the test module without the need of creating new directories and copying data. Signed-off-by: Martin Vrachev <[email protected]>
1 parent 2779954 commit 071622c

File tree

2 files changed

+166
-219
lines changed

2 files changed

+166
-219
lines changed

tests/test_api.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ def test_key_class(self):
333333
test_key_dict = key_dict.copy()
334334
del test_key_dict[key]
335335
with self.assertRaises(KeyError):
336-
Key.from_dict(test_key_dict)
336+
Key.from_dict("id", test_key_dict)
337337

338338

339339
def test_role_class(self):
@@ -357,7 +357,7 @@ def test_role_class(self):
357357
test_role_dict = role_dict.copy()
358358
del test_role_dict[role_attr]
359359
with self.assertRaises(KeyError):
360-
Key.from_dict(test_role_dict)
360+
Role.from_dict(test_role_dict)
361361

362362

363363
def test_metadata_root(self):

0 commit comments

Comments
 (0)