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

[MOHAMED] 100% coverage on both function's tests #4

Merged
merged 10 commits into from
Jun 26, 2024

Conversation

MoHuSh
Copy link
Collaborator

@MoHuSh MoHuSh commented Jun 26, 2024

Overview

Assigned functions:

  1. episode_status_icon in mygpo/web/templatetags/episodes.py
  2. class EpisodeUpdater (more specifically mark_outdated) in mygpo/data/feeddownloader.py

Testing for function assignments:

  1. mygpo/web/tests.py
  2. mygpo/data/tests.py

Results

There was no testing, covering or branch instrumentation for the functions I have been assigned. Given their relative cyclomatic complexity, and use within the repository this seemed like a higher priority set of functions to instrument, and complete coverage over.

Though by looking at the overall repository, we tend to see a pattern of mock django test classes being executed in */tests.py per directory.

I then used this pattern for testing to implement testing for episode_status_icon in mygpo/web/tests.py, and class_ EpisodeUpdater (more specifically it's function mark_outdated) in mygpo/data/tests.py.

Relative branch coverage reports, are automatically generated as episode_status_icon__coverage.txt and EPISODEUPDATER_mark_outdated_coverage.txt in the directory mygpo/coverage/mohamed.

Coverage improvements for the base files shown by coverage reports generated by coverage.py are shown below:

episodes.py:

Before instrumentation and testing episode_status_icon:
Screenshot 2024-06-25 130323

After instrumentation and testing episode_status_icon:
Screenshot 2024-06-25 125516

feeddownloader.py:

Before instrumentation and testing EpisodeUpdater:
Screenshot 2024-06-25 125616

After instrumentation and testing EpisodeUpdater:
Screenshot 2024-06-25 130424

- Implemented django mock tests for assumed branch cases on tests.py in web subdirectory of mygpo.
- Need to clarify, and add better manual branch instrumentation, for proper testing and coverage enhancment
- Completed manual instrumentation over branches, and enhanced testing in tests.py for coverage enhancement
Adjusted format for test implementation, instrumentation, and coverage to match team formatting, and specific output to a text file.
Final major adjustment to episode_status_icon testing. Changed coverage.txt file location to be a universal project root, rather than a local directory.

Full branch coverage achieved
Adjusted testing and instrumentation with additional helper methods to report coverage information to root
…ctions episode_status_icon and mark_outdated in class EpisodeUpdater

Completed instrumentation, testing and coverage, with coverage reporting functionality.

I have added additional instrumentation for hidden branches, and implicit branches.

Branch instrumentation for EpisodeUpdater was only applied to mark_outdated as they had the only functional instrumentable branches in the class, with tests checking functionality of Updater, and also mark_outdated for proper functionality in Django.

Please note, coverage.txt will be generated in the same directory of the test directory, regardless of local system. Please adjust as necessary to conform to team standards.
Had to change exporting behaviour for coverage reporting in accordance to team standards
…odeUpdater)

- Modified branch naming conventions
- Re-analysed and found instrumentatino and testing errors with EpisodeUpdater testing
Copy link
Collaborator

@andreas-stolle andreas-stolle left a comment

Choose a reason for hiding this comment

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

You did a very good job on testing your 2 functions and achieving 100% branch coverage. The functions were not easy and you managed testing them thoroughly and to get them running. Great work!

cls.mock_episode = Mock()
cls.mock_podcast = Mock()
cls.updater = EpisodeUpdater(cls.mock_episode, cls.mock_podcast)
cls.cumulative_branch_coverage = {"Branch 0": False, "Branch 1": False}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Good idea to use a map!

self.assertEqual(self.mock_episode.title, 'new-title')
self.assertTrue(self.mock_episode.save.called)

self.assertFalse(self.updater.branch_coverage["Branch 0"])
Copy link
Collaborator

Choose a reason for hiding this comment

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

You didn't need to assert the branch coverage values, as they would be printed anyway on the file, but it does not negatively impact the code.

staticfiles_storage.url("delete.png"),
"%s%s%s"
% (_("This episode has been deleted"), date_string, device_string),
)
else:
coverage_data['Branch 11'] +=1 # Branch 12 taken, implicit branch
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nice job at covering all branches.

self.assertEqual(result, mark_safe(expected))

def test_unknown_action(self):
action = Action(action='unknown')
Copy link
Collaborator

Choose a reason for hiding this comment

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

Very thought through test cases!

@andreas-stolle andreas-stolle merged commit 1b9fe85 into master Jun 26, 2024
@HusseinSarrar05 HusseinSarrar05 deleted the 4-manual-coverage-mohamed branch June 26, 2024 20:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants