Skip to content
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

Merged
merged 7 commits into from
Oct 24, 2024
Merged

Unit test/items py #74

merged 7 commits into from
Oct 24, 2024

Conversation

mugdhadhole1
Copy link
Contributor

Unit tests for items.py file

@mugdhadhole1 mugdhadhole1 requested a review from a team as a code owner September 13, 2024 10:04
@mugdhadhole1 mugdhadhole1 requested review from phiwuu and christophkloeffel and removed request for christophkloeffel September 13, 2024 10:07
Comment on lines 7 to 111
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"])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Few observations over here

  1. 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.
  2. 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.

@phiwuu phiwuu added the internal Affects the CI, tests or refactorings only, not relevant to the end-user label Oct 4, 2024
@@ -63,4 +63,3 @@ Written output for 3 items to basic.lobster
"schema": "lobster-imp-trace",
"version": 3
}

Copy link
Member

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?

Copy link
Contributor Author

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
}

Copy link
Member

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?

Copy link
Contributor Author

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

@mugdhadhole1 mugdhadhole1 force-pushed the unit-test/items-py branch 4 times, most recently from 3ab710b to 108e683 Compare October 11, 2024 14:18
Comment on lines 164 to 171
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"
Copy link
Contributor

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.

Copy link
Contributor

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.

@mugdhadhole1 mugdhadhole1 force-pushed the unit-test/items-py branch 2 times, most recently from 9f7e965 to 7e1d016 Compare October 17, 2024 14:18
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
@phiwuu phiwuu force-pushed the unit-test/items-py branch from 7e1d016 to 5743f13 Compare October 24, 2024 09:23
@phiwuu phiwuu merged commit f09cc93 into main Oct 24, 2024
21 checks passed
@phiwuu phiwuu deleted the unit-test/items-py branch October 24, 2024 09:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
internal Affects the CI, tests or refactorings only, not relevant to the end-user
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants