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

Implement a proper testing framework (GSoC23) #1101

Merged
merged 30 commits into from Aug 18, 2023

Conversation

afrid18
Copy link
Contributor

@afrid18 afrid18 commented Aug 8, 2023

Overview

This PR is intended work of Google Summer of Code 2023 Project assigned to me.

This project aims to get rid of binary rpm packages that are being used solely for testing rpmlint codebase. Since RPM packages consume relatively more space and more time to run tests, mocking them is a way to get rid of those heavy binary rpm files and make test little more efficient.

Description

In this PR, I have mainly worked on PythonCheck tests, DuplicatesCheck tests and ConfigFilesCheck tests which I eventually able to remove 18 binary files after mocking those tests. This approach can be carry forwarded to other checks as well.


Note: This is a copy of previous pull request:

test/test_config_files.py Fixed Show resolved Hide resolved
Copy link
Member

@danigm danigm left a comment

Choose a reason for hiding this comment

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

Looks pretty good. We can try to do some small improvements before merging it:

  • Add a new file test/README.md with some basic documentation about get_tested_mock_package and how to use it. Basically a guide to how to write new tests.
  • Review default values in FakePkg and remove from tests when it's not needed, for example {'content': ''}, could just be {}, to create just the file with default values.
  • Create common fake packages to reuse in different tests, for example test/mocks/packages.py and there we can have the fake packages defined like config_files, bad_crc_uncompressed, python3_icecream_leftovers, etc. So in tests we just need to import. We can do this just for packages that are useful in more than one test and for "large" fake package definitions.

In the future we can add even more improvements like start to use the faker module to randomize some of the fake data, like file content and other data.

This is my first pull request on how I have tried to mock a test,
I used FakePkg class and tried to modify an existing test. I have
created a new helper function get_tested_mock_package which helps
to create a FakePkg obj, this object is further passed to tests.
modified to use dict methods in get_tested_mock_package
Test that required FakePkg has been abstracted and hence do not necessarily need to be imported
This commit removes two binary rpm files that were used for testing docs and docs modules in python packages, for which tests are mocking has been implemented
In add_file_with_content function, changes were made to check for any type prior it was only checked for True
created an another test (test_python_dependencies_metadata2) which helps to get rid of a binary file python310-jupyter-server-fileid-0.9.0-7.2.noarch.rpm
In this commit, I have mocked another metadata test, that checks for metadata content in python packages. With this test we can get rid of binary file: python310-scikit-build-0.17.2-41.1.noarch.rpm. The new test function is test_python_dependencies_metadata3
…tatements

In this commit, I have completely removed previous paramatrized tests for 5 binaries, and also added another test test_python_dependencies_metadata4
As this is managed by PR-CI, No need of checking them again on branch
Pkg and FakePkg both use _gather_dep_info and _gather_aux
so moved them to their parent class AbstractPkg
…ested_mock_package

Added a new helper method in FakePkg called create_files
this will avoid if else chain in get_tested_mock_package utility
added a new helper method in FakePkg class which
is  initiate_files_base_data, this is used to initiate
fakepkg class with basic files data after setting
up custom metadata;
removed a binary
other binary is required for  file
removed binary test/binary/python39-blinker-1.6.2
There are total 2 tests and 2 binaries
one binary test/binary/config-files-1.0-0.x86_64.rpm
is removed and another binary test/binary/logrotate-0-0.x86_64.rpm
is used by test/test_logrotate.py and hence it isn't removed
each file by default created empty content;
no need to mention create_dir as False; by
default it is false
@afrid18
Copy link
Contributor Author

afrid18 commented Aug 18, 2023

Looks pretty good. We can try to do some small improvements before merging it:

  • Add a new file test/README.md with some basic documentation about get_tested_mock_package and how to use it. Basically a guide to how to write new tests.
  • Review default values in FakePkg and remove from tests when it's not needed, for example {'content': ''}, could just be {}, to create just the file with default values.
  • Create common fake packages to reuse in different tests, for example test/mocks/packages.py and there we can have the fake packages defined like config_files, bad_crc_uncompressed, python3_icecream_leftovers, etc. So in tests we just need to import. We can do this just for packages that are useful in more than one test and for "large" fake package definitions.

In the future we can add even more improvements like start to use the faker module to randomize some of the fake data, like file content and other data.

  • Add a new file test/README.md with some basic documentation about get_tested_mock_package and how to use it. Basically a guide to how to write new tests.
  • Add a new file test/README.md with some basic documentation about get_tested_mock_package and how to use it. Basically a guide to how to write new tests.
  • Create common fake packages to reuse in different tests, for example test/mocks/packages.py and there we can have the fake packages defined like config_files, bad_crc_uncompressed, python3_icecream_leftovers, etc. So in tests we just need to import. We can do this just for packages that are useful in more than one test and for "large" fake package definitions.

I will work on this in future. So for now, I think its time to open this pr for review.

@afrid18 afrid18 marked this pull request as ready for review August 18, 2023 12:02
@danigm danigm merged commit 3b34b29 into rpm-software-management:main Aug 18, 2023
13 checks passed
@danigm
Copy link
Member

danigm commented Aug 18, 2023

Good work! Let's merge this and continue working on test improvements in following pull requests

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.

None yet

2 participants