This project implements a FizzBuzz function and includes unit tests for it. It also provides a CI/CD configuration to run the unit tests and generate a coverage report.
The project has the following files and directories:
-
fizzbuzz/__init__.py
: An empty file that marks thefizzbuzz
directory as a Python package. -
fizzbuzz/fizzbuzz.py
: Contains the implementation of thefizzbuzz
function. This function takes an integer as input and returns a string based on the FizzBuzz rules. -
tests/__init__.py
: An empty file that marks thetests
directory as a Python package. -
tests/test_fizzbuzz.py
: Contains the unit tests for thefizzbuzz
function. It uses a testing framework likeunittest
orpytest
to define test cases and assertions. -
.github/workflows/ci.yml
: The configuration file for the CI/CD workflow. It specifies the steps to run the unit tests and generate a coverage report. It uses a CI/CD platform like GitHub Actions to automate the process. -
.coveragerc
: The configuration file for the coverage report. It specifies the settings for the coverage analysis, such as which files to include or exclude from the report. -
requirements.txt
: Lists the dependencies required for the project. It includes the packages needed for testing and generating the coverage report.
The fizzbuzz
function is implemented in the fizzbuzz/fizzbuzz.py
file. It takes an integer as input and returns a string based on the following rules:
- If the number is divisible by 3, it returns "Fizz".
- If the number is divisible by 5, it returns "Buzz".
- If the number is divisible by both 3 and 5, it returns "FizzBuzz".
- Otherwise, it returns the input number as a string.
The unit tests for the fizzbuzz
function are implemented in the tests/test_fizzbuzz.py
file. They use the unittest
framework to define test cases and assertions. The tests cover different scenarios to ensure the correct behavior of the fizzbuzz
function.
The CI/CD configuration is defined in the .github/workflows/ci.yml
file. It specifies the steps to run the unit tests and generate a coverage report using a CI/CD platform like GitHub Actions. The configuration ensures that the tests are executed automatically whenever changes are pushed to the repository.
The coverage report is generated based on the settings specified in the .coveragerc
file. It includes information about the code coverage of the project, indicating which parts of the code are covered by the unit tests.
To run the unit tests locally, follow these steps:
- Clone the repository to your local machine.
- Install the project dependencies by running
pip install -r requirements.txt
. - Navigate to the project root directory.
- Run the command
python -m unittest discover tests
to execute the unit tests.
To generate the coverage report locally, follow these steps:
- Ensure that the project dependencies are installed (see previous section).
- Navigate to the project root directory.
- Run the command
coverage run -m unittest discover tests
to execute the unit tests and collect coverage data. - Run the command
coverage report
to display the coverage report in the console. - Optionally, run the command
coverage html
to generate an HTML report in thehtmlcov
directory.
That's it! You now have a FizzBuzz project with unit tests and a CI/CD configuration to run the tests and generate a coverage report. Happy coding!