-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unit test/items py #74
Conversation
test-unit/test_items.py
Outdated
mock_name = "mock_name" | ||
mock_text = "mock_text" | ||
mock_status = "active" | ||
mock_language = "mock_language" | ||
mock_location = create_autospec(Location, instance = True) | ||
tracing_tag = Tracing_Tag(mock_namespace, mock_tag) | ||
item = Item(tracing_tag, mock_location) | ||
requirement = Requirement(tracing_tag, mock_location, mock_framework, mock_kind, mock_name, mock_text, mock_status) | ||
implementation = Implementation(tracing_tag, mock_location, mock_language, mock_kind, mock_name) | ||
activity = Activity(tracing_tag, mock_location, mock_framework, mock_kind) | ||
|
||
@patch("lobster.items.Tracing_Tag.from_json") | ||
def setup_test_from_json(self, class_name, mock_from_json): | ||
mock_level = "mock_level" | ||
mock_schema_version = 3 | ||
mock_from_json.return_value = self.tracing_tag | ||
for location_type in ["file", "github", "codebeamer", "void"]: | ||
with self.subTest(location_type): | ||
if location_type == "file": | ||
location_data = { | ||
"kind": location_type, | ||
"file": "example.txt" | ||
} | ||
elif location_type == "github": | ||
location_data = { | ||
"kind": location_type, | ||
"gh_root": "https://mysuperserver.com", | ||
"commit": "commit string", | ||
"file": "example.txt", | ||
"line": 1 | ||
} | ||
elif location_type == "codebeamer": | ||
location_data = { | ||
"kind": location_type, | ||
"cb_root": "https://mysuperserver.com", | ||
"tracker": 1, | ||
"item": 1, | ||
"version": 1, | ||
"name": "name string" | ||
} | ||
elif location_type == "void": | ||
location_data = { | ||
"kind": location_type | ||
} | ||
if class_name == "TestActivity": | ||
mock_data = { | ||
"tag": self.tracing_tag, | ||
"location": location_data, | ||
"framework": "framework_data", | ||
"kind": "kind_data", | ||
"status": None | ||
} | ||
result = self.activity.from_json(mock_level, mock_data, mock_schema_version) | ||
self.assertEqual(result.tag, self.tracing_tag) | ||
self.assertEqual(result.framework, "framework_data") | ||
self.assertEqual(result.kind, "kind_data") | ||
self.assertEqual(result.status, None) | ||
elif class_name == "TestImplementation": | ||
mock_data = { | ||
"tag": self.tracing_tag, | ||
"location": location_data, | ||
"language": "Python", | ||
"kind": "kind_data", | ||
"name": "name_data", | ||
} | ||
result = self.implementation.from_json(mock_level, mock_data, mock_schema_version) | ||
self.assertEqual(result.tag, self.tracing_tag) | ||
self.assertEqual(result.language, "Python") | ||
self.assertEqual(result.kind, "kind_data") | ||
self.assertEqual(result.name, "name_data") | ||
elif class_name == "TestRequirement": | ||
mock_data = { | ||
"tag": self.tracing_tag, | ||
"location": location_data, | ||
"framework": "framework_data", | ||
"kind": "kind_data", | ||
"name": "name_data", | ||
"text": "text_data", | ||
"status": "status_data" | ||
} | ||
result = self.requirement.from_json(mock_level, mock_data, mock_schema_version) | ||
self.assertEqual(result.tag, self.tracing_tag) | ||
self.assertEqual(result.framework, "framework_data") | ||
self.assertEqual(result.kind, "kind_data") | ||
self.assertEqual(result.name, "name_data") | ||
self.assertEqual(result.text, "text_data") | ||
self.assertEqual(result.status, "status_data") | ||
if location_type == "file": | ||
self.assertEqual(result.location.filename, location_data["file"]) | ||
elif location_type == "github": | ||
self.assertEqual(result.location.gh_root, location_data["gh_root"]) | ||
self.assertEqual(result.location.commit, location_data["commit"]) | ||
self.assertEqual(result.location.filename, location_data["file"]) | ||
self.assertEqual(result.location.line, location_data["line"]) | ||
elif location_type == "codebeamer": | ||
self.assertEqual(result.location.cb_root, location_data["cb_root"]) | ||
self.assertEqual(result.location.tracker, location_data["tracker"]) | ||
self.assertEqual(result.location.item, location_data["item"]) | ||
self.assertEqual(result.location.version, location_data["version"]) | ||
self.assertEqual(result.location.name, location_data["name"]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Few observations over here
- This class is basically used to test the LOBSTER items classes, so my suggestion would be to create separate test case for every LOBSTER item class. Same implementation as that is done in classes TestRequirement or TestItem etc.
- The class name can be more relevant to the tests it has. Setup is generally used as a test fixture to prepare and do the pre test activities.
@@ -63,4 +63,3 @@ Written output for 3 items to basic.lobster | |||
"schema": "lobster-imp-trace", | |||
"version": 3 | |||
} | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this change really necessary?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Previously make test-ci command added two empty lines at the end of the content in output files
I made this change to remove the extra lines.
In recent commit, I have removed the code which added extra empty line to the end of content in output files,
now you will see only one empty line at the end of content in those output files
@@ -48,4 +48,3 @@ Written output for 2 items to pytest_mark.lobster | |||
"schema": "lobster-act-trace", | |||
"version": 3 | |||
} | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this change really necessary?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Previously make test-ci command added two empty lines at the end of the content in output files
I made this change to remove the extra lines.
In recent commit, I have removed the code which added extra empty line to the end of content in output files,
now you will see only one empty line at the end of content in those output files
3ab710b
to
108e683
Compare
test-unit/test_items.py
Outdated
SetUp.item.ref_up = [] | ||
SetUp.item.ref_down = [SetUp.tracing_tag] | ||
SetUp.item.just_up = [] | ||
SetUp.item.just_down = [] | ||
SetUp.item.just_global = [] | ||
SetUp.item.messages = [] | ||
SetUp.item.has_error = False | ||
SetUp.item.level = "level1" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just inherit the SetUp class and access these through self.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should add blank lines to separate logical sections and avoid adding unnecessary blank lines in-between the code.
9f7e965
to
7e1d016
Compare
Separate test for test_from_json function of each class and renamed the function from setup_test_from_json to set_location_data
…iles Previously make test-ci command added two empty lines at the end of the content in output files now you will see only see one empty line at the end of the content in those output files I have also done some linting changes
…self Renamed Setup to ItemsTests and inherited it and accessed properties and methods using self Removed extra spaces, unnecessary blank lines and used blank lines where necessary
7e1d016
to
5743f13
Compare
Unit tests for items.py file