Skip to content

fix: simplify repository and update deps #68

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

Merged
merged 7 commits into from
Jun 7, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
fix: simplify repository and update deps
  • Loading branch information
thomasrockhu-codecov committed Jun 7, 2022
commit da7fb8db88a9266469f81019fbeb66f7e4d080fe
8 changes: 3 additions & 5 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
version: 2.1
orbs:
codecov: codecov/codecov@3.0.0
codecov: codecov/codecov@3

jobs:
build:
docker:
- image: cimg/python:3.9.6
- image: cimg/python:3.10
steps:
- checkout
- run:
name: Install dependencies
command: pip install -r requirements.txt
- run:
name: Run tests and collect coverage
command: |
coverage run tests.py
coverage xml
command: pytest --cov app
- codecov/upload

workflow:
Expand Down
Binary file added .coverage
Binary file not shown.
10 changes: 4 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,13 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Set up Python 3.9
- name: Set up Python 3.10
uses: actions/setup-python@v2
with:
python-version: 3.9
python-version: 3.10
- name: Install dependencies
run: pip install -r requirements.txt
- name: Run tests and collect coverage
run: |
coverage run tests.py
coverage xml
run: pytest --cov app
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v2
uses: codecov/codecov-action@v3
82 changes: 3 additions & 79 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,91 +1,15 @@
# [Codecov](https://codecov.io) Python Example
[![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2Fcodecov%2Fexample-python.svg?type=shield)](https://app.fossa.com/projects/git%2Bgithub.com%2Fcodecov%2Fexample-python?ref=badge_shield)


## Guide

### GitHub Actions
A minimal configuration might look like:

```yml
steps:
# (Other steps go here)
- name: "Upload coverage to Codecov"
uses: codecov/codecov-action@v2
with:
fail_ci_if_error: true
token: ${{ secrets.CODECOV_TOKEN }} # not required for public repos
```

See [codecov/codecov-action](https://github.com/codecov/codecov-action) for
more information, a [detailed example](https://github.com/codecov/codecov-action#example-workflowyml-with-codecov-action),
and other options.

### Produce Coverage Reports
[coverage.py](https://github.com/nedbat/coveragepy) is required to collect coverage metrics.

Below are some examples on how to include coverage tracking during your tests. You will need to call `coverage xml` to generate the coverage xml output, which will be archived and processed server side.

You may need to configure a `.coveragerc` file. Learn more [here](http://coverage.readthedocs.org/en/latest/config.html). Start with this [generic .coveragerc](https://gist.github.com/codecov-io/bf15bde2c7db1a011b6e) for example.

We highly suggest adding `source` to your `.coveragerc` which solves a number of issues collecting coverage.

```ini
[run]
source=your_package_name
```
#### unittests
```
pip install coverage
coverage run tests.py
```
#### pytest
```
pip install pytest-cov
pytest --cov=./
```
#### nosetests
```
nosetest --with-coverage
```
See the [Offical Nose coverage docs](http://nose.readthedocs.org/en/latest/plugins/cover.html) for more information.

### Testing with ``tox``

Codecov can be run from inside your `tox.ini` please make sure you pass all the necessary environment variables through:
```ini
[testenv]
passenv = CI TRAVIS TRAVIS_*
deps = codecov
commands = codecov
```

### FAQ
- Q: What's the difference between the codecov-bash and codecov-python uploader?
A: As far as python is concerned, *nothing*. You may choose to use either uploader. Codecov recommends **using the bash uploader when possible** as it supports more unique repository setups. Learn more at [codecov/codecov-bash](https://github.com/codecov/codecov-bash) and [codecov/codecov-python](https://github.com/codecov/codecov-python).
- Q: Why am I seeing `No data to report`?
A: This output is written by running the command `coverage xml` and states that there were no `.coverage` files found.
1. Make sure coverage is enabled. See Enabling Coverage
2. You may need to run `coverage combine` before running Codecov.
3. Using Docker? Please follow this step: [Testing with Docker: Codecov Inside Docker](https://docs.codecov.io/docs/testing-with-docker#codecov-inside-docker).
- Q: Can I upload my `.coverage` files?
A: **No**, these files contain coverage data but are not properly mapped back to the source code. We rely on `coveragepy` to handle this by calling `coverage xml` in the uploader.

## Caveats
### Private Repo
Repository tokens are required for (a) all private repos, (b) public repos not using the GitHub Actions, Travis CI, CircleCI or AppVeyor.

Find your repository token at Codecov and provide via appending `-t <your upload token>` to you where you upload reports.

### Cobertura Reports
Cobertura reports can expire - Codecov will reject reports that are older than 12 hours. The logs contain details if a report expired.
This example repository shows how Codecov can be integrated with a simple python project. For more information, please see the links below.

## Links
- [Quick Start](https://docs.codecov.com/docs/quick-start)
- [GitHub Tutorial](https://docs.codecov.com/docs/github-tutorial)
- [Community Boards](https://community.codecov.io)
- [Support](https://codecov.io/support)
- [Documentation](https://docs.codecov.io)



## License
[![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2Fcodecov%2Fexample-python.svg?type=large)](https://app.fossa.com/projects/git%2Bgithub.com%2Fcodecov%2Fexample-python?ref=badge_large)
Empty file added app/__init__.py
Empty file.
Binary file added app/__pycache__/__init__.cpython-39.pyc
Binary file not shown.
Binary file added app/__pycache__/calculator.cpython-39.pyc
Binary file not shown.
Binary file not shown.
14 changes: 14 additions & 0 deletions app/calculator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
class Calculator:
def add(x, y):
return x + y

def subtract(x, y):
return x - y

def multiply(x, y):
return x * y

def divide(x, y):
if y == 0:
return 'Cannot divide by 0'
return x * 1.0 / y
31 changes: 31 additions & 0 deletions app/test_calculator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
from .calculator import Calculator


def test_add():
assert Calculator.add(1, 2) == 3.0
assert Calculator.add(1.0, 2.0) == 3.0
assert Calculator.add(0, 2.0) == 2.0
assert Calculator.add(2.0, 0) == 2.0
assert Calculator.add(-4, 2.0) == -2.0

def test_subtract():
assert Calculator.subtract(1, 2) == -1.0
assert Calculator.subtract(2, 1) == 1.0
assert Calculator.subtract(1.0, 2.0) == -1.0
assert Calculator.subtract(0, 2.0) == -2.0
assert Calculator.subtract(2.0, 0.0) == 2.0
assert Calculator.subtract(-4, 2.0) == -6.0

def test_multiply():
assert Calculator.multiply(1, 2) == 2.0
assert Calculator.multiply(1.0, 2.0) == 2.0
assert Calculator.multiply(0, 2.0) == 0.0
assert Calculator.multiply(2.0, 0.0) == 0.0
assert Calculator.multiply(-4, 2.0) == -8.0

def test_divide():
assert Calculator.divide(1, 2) == 0.5
assert Calculator.divide(1.0, 2.0) == 0.5
assert Calculator.divide(0, 2.0) == 0
assert Calculator.divide(2.0, 0.0) == 'Cannot divide by 0'
assert Calculator.divide(-4, 2.0) == -2.0
5 changes: 0 additions & 5 deletions awesome/__init__.py

This file was deleted.

2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
coverage
coverage==6.4.1
6 changes: 6 additions & 0 deletions tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ class TestMethods(unittest.TestCase):
def test_add(self):
self.assertEqual(awesome.smile(), ":)")

def test_add_again(self):
self.assertEqual(awesome.smile(), ":)")

def test_if(self):
self.assertTrue(awesome.test_if(1))


if __name__ == '__main__':
unittest.main()
1 change: 0 additions & 1 deletion time.txt

This file was deleted.