Skip to content

Commit da7fb8d

Browse files
fix: simplify repository and update deps
1 parent c29bb83 commit da7fb8d

14 files changed

+62
-97
lines changed

.circleci/config.yml

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,19 @@
11
version: 2.1
22
orbs:
3-
codecov: codecov/codecov@3.0.0
3+
codecov: codecov/codecov@3
44

55
jobs:
66
build:
77
docker:
8-
- image: cimg/python:3.9.6
8+
- image: cimg/python:3.10
99
steps:
1010
- checkout
1111
- run:
1212
name: Install dependencies
1313
command: pip install -r requirements.txt
1414
- run:
1515
name: Run tests and collect coverage
16-
command: |
17-
coverage run tests.py
18-
coverage xml
16+
command: pytest --cov app
1917
- codecov/upload
2018

2119
workflow:

.coverage

52 KB
Binary file not shown.

.github/workflows/ci.yml

+4-6
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,13 @@ jobs:
66
steps:
77
- name: Checkout
88
uses: actions/checkout@v2
9-
- name: Set up Python 3.9
9+
- name: Set up Python 3.10
1010
uses: actions/setup-python@v2
1111
with:
12-
python-version: 3.9
12+
python-version: 3.10
1313
- name: Install dependencies
1414
run: pip install -r requirements.txt
1515
- name: Run tests and collect coverage
16-
run: |
17-
coverage run tests.py
18-
coverage xml
16+
run: pytest --cov app
1917
- name: Upload coverage to Codecov
20-
uses: codecov/codecov-action@v2
18+
uses: codecov/codecov-action@v3

README.md

+3-79
Original file line numberDiff line numberDiff line change
@@ -1,91 +1,15 @@
11
# [Codecov](https://codecov.io) Python Example
22
[![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)
33

4-
5-
## Guide
6-
7-
### GitHub Actions
8-
A minimal configuration might look like:
9-
10-
```yml
11-
steps:
12-
# (Other steps go here)
13-
- name: "Upload coverage to Codecov"
14-
uses: codecov/codecov-action@v2
15-
with:
16-
fail_ci_if_error: true
17-
token: ${{ secrets.CODECOV_TOKEN }} # not required for public repos
18-
```
19-
20-
See [codecov/codecov-action](https://github.com/codecov/codecov-action) for
21-
more information, a [detailed example](https://github.com/codecov/codecov-action#example-workflowyml-with-codecov-action),
22-
and other options.
23-
24-
### Produce Coverage Reports
25-
[coverage.py](https://github.com/nedbat/coveragepy) is required to collect coverage metrics.
26-
27-
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.
28-
29-
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.
30-
31-
We highly suggest adding `source` to your `.coveragerc` which solves a number of issues collecting coverage.
32-
33-
```ini
34-
[run]
35-
source=your_package_name
36-
```
37-
#### unittests
38-
```
39-
pip install coverage
40-
coverage run tests.py
41-
```
42-
#### pytest
43-
```
44-
pip install pytest-cov
45-
pytest --cov=./
46-
```
47-
#### nosetests
48-
```
49-
nosetest --with-coverage
50-
```
51-
See the [Offical Nose coverage docs](http://nose.readthedocs.org/en/latest/plugins/cover.html) for more information.
52-
53-
### Testing with ``tox``
54-
55-
Codecov can be run from inside your `tox.ini` please make sure you pass all the necessary environment variables through:
56-
```ini
57-
[testenv]
58-
passenv = CI TRAVIS TRAVIS_*
59-
deps = codecov
60-
commands = codecov
61-
```
62-
63-
### FAQ
64-
- Q: What's the difference between the codecov-bash and codecov-python uploader?
65-
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).
66-
- Q: Why am I seeing `No data to report`?
67-
A: This output is written by running the command `coverage xml` and states that there were no `.coverage` files found.
68-
1. Make sure coverage is enabled. See Enabling Coverage
69-
2. You may need to run `coverage combine` before running Codecov.
70-
3. Using Docker? Please follow this step: [Testing with Docker: Codecov Inside Docker](https://docs.codecov.io/docs/testing-with-docker#codecov-inside-docker).
71-
- Q: Can I upload my `.coverage` files?
72-
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.
73-
74-
## Caveats
75-
### Private Repo
76-
Repository tokens are required for (a) all private repos, (b) public repos not using the GitHub Actions, Travis CI, CircleCI or AppVeyor.
77-
78-
Find your repository token at Codecov and provide via appending `-t <your upload token>` to you where you upload reports.
79-
80-
### Cobertura Reports
81-
Cobertura reports can expire - Codecov will reject reports that are older than 12 hours. The logs contain details if a report expired.
4+
This example repository shows how Codecov can be integrated with a simple python project. For more information, please see the links below.
825

836
## Links
7+
- [Quick Start](https://docs.codecov.com/docs/quick-start)
8+
- [GitHub Tutorial](https://docs.codecov.com/docs/github-tutorial)
849
- [Community Boards](https://community.codecov.io)
8510
- [Support](https://codecov.io/support)
8611
- [Documentation](https://docs.codecov.io)
8712

8813

89-
9014
## License
9115
[![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)

app/__init__.py

Whitespace-only changes.
156 Bytes
Binary file not shown.
847 Bytes
Binary file not shown.
Binary file not shown.

app/calculator.py

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
class Calculator:
2+
def add(x, y):
3+
return x + y
4+
5+
def subtract(x, y):
6+
return x - y
7+
8+
def multiply(x, y):
9+
return x * y
10+
11+
def divide(x, y):
12+
if y == 0:
13+
return 'Cannot divide by 0'
14+
return x * 1.0 / y

app/test_calculator.py

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
from .calculator import Calculator
2+
3+
4+
def test_add():
5+
assert Calculator.add(1, 2) == 3.0
6+
assert Calculator.add(1.0, 2.0) == 3.0
7+
assert Calculator.add(0, 2.0) == 2.0
8+
assert Calculator.add(2.0, 0) == 2.0
9+
assert Calculator.add(-4, 2.0) == -2.0
10+
11+
def test_subtract():
12+
assert Calculator.subtract(1, 2) == -1.0
13+
assert Calculator.subtract(2, 1) == 1.0
14+
assert Calculator.subtract(1.0, 2.0) == -1.0
15+
assert Calculator.subtract(0, 2.0) == -2.0
16+
assert Calculator.subtract(2.0, 0.0) == 2.0
17+
assert Calculator.subtract(-4, 2.0) == -6.0
18+
19+
def test_multiply():
20+
assert Calculator.multiply(1, 2) == 2.0
21+
assert Calculator.multiply(1.0, 2.0) == 2.0
22+
assert Calculator.multiply(0, 2.0) == 0.0
23+
assert Calculator.multiply(2.0, 0.0) == 0.0
24+
assert Calculator.multiply(-4, 2.0) == -8.0
25+
26+
def test_divide():
27+
assert Calculator.divide(1, 2) == 0.5
28+
assert Calculator.divide(1.0, 2.0) == 0.5
29+
assert Calculator.divide(0, 2.0) == 0
30+
assert Calculator.divide(2.0, 0.0) == 'Cannot divide by 0'
31+
assert Calculator.divide(-4, 2.0) == -2.0

awesome/__init__.py

-5
This file was deleted.

requirements.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
coverage
1+
coverage==6.4.1

tests.py

+6
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ class TestMethods(unittest.TestCase):
77
def test_add(self):
88
self.assertEqual(awesome.smile(), ":)")
99

10+
def test_add_again(self):
11+
self.assertEqual(awesome.smile(), ":)")
12+
13+
def test_if(self):
14+
self.assertTrue(awesome.test_if(1))
15+
1016

1117
if __name__ == '__main__':
1218
unittest.main()

time.txt

-1
This file was deleted.

0 commit comments

Comments
 (0)