Skip to content

Commit 9661849

Browse files
author
thenamesweretakenalready
committed
🎨 Fully integrate Poetry, fix tests
1 parent ee087e8 commit 9661849

File tree

5 files changed

+196
-129
lines changed

5 files changed

+196
-129
lines changed

.circleci/config.yml

Lines changed: 86 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,100 @@
1-
# Python CircleCI 2.0 configuration file
1+
# https://gist.github.com/jonatasbaldin/b0eba2ac8ee887ca27ee811697d4d73b
22
version: 2
3-
workflows:
4-
version: 2
5-
test:
6-
jobs:
7-
- test-3.8
8-
- test-3.6
93

104
jobs:
11-
test-3.8: &tests
5+
6+
# Building and testing the project
7+
# Useful when a PR is open, for example
8+
build-and-test:
9+
# Our environment, Python 3.6.8
1210
docker:
1311
- image: circleci/python:3.8
1412

15-
working_directory: ~/repo
16-
13+
# The steps for our build-and-test
1714
steps:
18-
# Step 1: obtain repo from GitHub
15+
# Get the code
1916
- checkout
20-
# Step 2: create virtual env and install dependencies
17+
18+
# Cache can be tricky at first, but this means
19+
# Please, restore my cache (what is actually on the cache will be defined later)
20+
# if the text key `deps-{{ checksum "poetry.lock" }}` changes (and it WILL change everytime poetry.lock is updated since we rely on its checksum)
21+
# and poetry.lock is updated every time we add a new dependency to our project
22+
- restore_cache:
23+
keys:
24+
- deps-{{ checksum "poetry.lock" }}
25+
26+
# Let's install the dependencies
2127
- run:
22-
name: install dependencies
28+
name: Install Dependencies
2329
command: |
24-
python -m venv venv
25-
. venv/bin/activate
26-
pip install -r requirements.txt
27-
# Step 3: run linter and tests
30+
poetry install
31+
32+
# Save's the specified path as a cache. This is the path Poetry uses to install the dependencies
33+
# So if you don't install anything new, this folder won't change and the cache will be effective
34+
- save_cache:
35+
key: deps-{{ checksum "poetry.lock" }}
36+
paths:
37+
- /home/circleci/.cache/pypoetry/virtualenvs
38+
39+
# Another step, run flake8
40+
- run:
41+
name: Run flake8
42+
command: |
43+
poetry run flake8 .
44+
45+
# Last step, runs our tests ommiting the dependencies path (so we don't take their coverage into account)
46+
# And send our coverage somewhere, in this case, coveralls
2847
- run:
29-
name: run tests
48+
name: Run Pytest, report coverage
3049
command: |
31-
. venv/bin/activate
32-
python tests/test_main.py
50+
poetry run coverage run --omit="/home/circleci/.cache/pypoetry/virtualenvs" -m pytest
51+
poetry run coveralls
3352
34-
test-3.6:
35-
<<: *tests
53+
# This is the definition of another job, the one we use to publish the package to PyPI
54+
deployment:
55+
56+
# Same environment
3657
docker:
37-
- image: circleci/python:3.6
58+
- image: circleci/python:3.6.8
59+
steps:
60+
61+
# Gets the code
62+
- checkout
63+
64+
# Use `poetry publish` to Publish he package using username and password from CircleCI environment variables
65+
# Which can be configured inside CircleCI's interface
66+
- run:
67+
name: Push to PyPI
68+
command: |
69+
poetry publish --build --username "${PYPI_USERNAME}" --password "${PYPI_PASSWORD}" --no-interaction
70+
71+
# In the workflows section, we specify when we want to run the jobs defined
72+
workflows:
73+
version: 2
74+
75+
# The build-and-test we will run EVERYTIME a piece of code changes
76+
build-and-test-workflow:
77+
jobs:
78+
- build-and-test
79+
80+
# The deployment workflow publishes the package
81+
deployment-workflow:
82+
jobs:
83+
84+
# Runs build and test, but now just on Git tags (created from a GitHub release)
85+
- build-and-test:
86+
filters:
87+
tags:
88+
only: /v[0-9]+(\.[0-9]+)*/
89+
branches:
90+
ignore: /.*/
91+
92+
# Runs the deployment job, just with the tags as well
93+
- deployment:
94+
requires:
95+
- build-and-test
96+
filters:
97+
tags:
98+
only: /v[0-9]+(\.[0-9]+)*/
99+
branches:
100+
ignore: /.*/t

pyproject.toml

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
[tool.poetry]
2-
name = "sv443s-jokeapi-python-wrapper"
3-
version = "0.1.0"
4-
description = ""
5-
authors = ["Leet Hakker <[email protected]>"]
2+
name = "jokeapi"
3+
version = "0.2.9"
4+
description = "An API wrapper for Sv443's JokeAPI"
5+
authors = ["leet hakker <[email protected]>"]
66

77
[tool.poetry.dependencies]
88
python = "^3.8"
@@ -17,5 +17,10 @@ mypy = "^0.790"
1717

1818

1919
[build-system]
20-
requires = ["poetry-core>=1.0.0"]
20+
requires = ["poetry-core>=1.0.0",
21+
"setuptools>=30.3.0,<50",
22+
"wheel",
23+
"pytest-runner",
24+
"setuptools_scm>=3.3.1",
25+
]
2126
build-backend = "poetry.core.masonry.api"
File renamed without changes.
File renamed without changes.

tests/test_main.py

Lines changed: 100 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
from os import getenv
2-
from jokeapi import Jokes
32
from dotenv import load_dotenv
3+
import sys, os
4+
5+
sys.path.append(os.path.join(os.path.dirname(__file__), os.pardir, "src"))
6+
from jokeapi import Jokes
47

58
load_dotenv()
69

@@ -9,103 +12,99 @@
912
token = getenv("token")
1013

1114

12-
try:
13-
j.get_joke()
14-
except Exception as e:
15-
errors.append({"Error in": "blank joke get", "Error": e})
16-
17-
"""Testing auth tokens"""
18-
try:
19-
j.get_joke(auth_token=token)
20-
except Exception as e:
21-
auth_token = None
22-
errors.append({"Error in": "auth usage", "Error": e})
23-
24-
"""Testing for errors in categories"""
25-
try:
26-
j.get_joke(category=["programming"], auth_token=token)
27-
except Exception as e:
28-
errors.append({"Error in": "category programming", "Error": e})
29-
try:
30-
j.get_joke(category=["misc"], auth_token=token)
31-
except Exception as e:
32-
errors.append({"Error in": "category miscellaneous", "Error": e})
33-
try:
34-
j.get_joke(category=["dark"], auth_token=token)
35-
except Exception as e:
36-
errors.append({"Error in": "category dark", "Error": e})
37-
38-
"""Testing for errors in blacklist"""
39-
try:
40-
j.get_joke(blacklist=["nsfw"], auth_token=token)
41-
except Exception as e:
42-
errors.append({"Error in": "blacklist nsfw", "Error": e})
43-
44-
try:
45-
j.get_joke(blacklist=["religious"], auth_token=token)
46-
except Exception as e:
47-
errors.append({"Error in": "blacklist religious", "Error": e})
48-
49-
try:
50-
j.get_joke(blacklist=["political"], auth_token=token)
51-
except Exception as e:
52-
errors.append({"Error in": "blacklist political", "Error": e})
53-
54-
try:
55-
j.get_joke(blacklist=["racist"], auth_token=token)
56-
except Exception as e:
57-
errors.append({"Error in": "blacklist political", "Error": e})
58-
59-
try:
60-
j.get_joke(blacklist=["sexist"], auth_token=token)
61-
except Exception as e:
62-
errors.append({"Error in": "blacklist sexist", "Error": e})
63-
64-
65-
"""Testing for errors in response_format"""
66-
try:
67-
j.get_joke(response_format="xml", auth_token=token)
68-
except Exception as e:
69-
errors.append({"Error in": "response_format xml", "Error": e})
70-
71-
try:
72-
j.get_joke(response_format="yaml", auth_token=token)
73-
except Exception as e:
74-
errors.append({"Error in": "response_format yaml", "Error": e})
75-
76-
77-
"""Testing for errors in type"""
78-
try:
79-
j.get_joke(joke_type="single", auth_token=token)
80-
except Exception as e:
81-
errors.append({"Error in": "type single", "Error": e})
82-
83-
try:
84-
j.get_joke(joke_type="twopart", auth_token=token)
85-
except Exception as e:
86-
errors.append({"Error in": "type double", "Error": e})
87-
88-
89-
"""Testing for errors in search_string"""
90-
try:
91-
j.get_joke(search_string="search", auth_token=token)
92-
# as long as this gets a response, the api wrapper is fine;
93-
# it probably doesn't exist in a joke.
94-
except Exception as e:
95-
errors.append({"Error in": "search_string", "Error": e})
96-
97-
98-
"""Testing for errors in id_range"""
99-
try:
100-
j.get_joke(id_range=[30, 151], auth_token=token)
101-
except Exception as e:
102-
errors.append({"Error in": "id_range", "Error": e})
103-
104-
105-
if len(errors):
106-
for e in errors:
107-
print(f"Error in: {e['Error in']}\nError: {e['Error']}")
108-
if len(errors) == 1:
109-
raise Exception("1 error occured")
110-
111-
raise Exception(f"{len(errors)} errors occurred")
15+
def test_main():
16+
try:
17+
j.get_joke()
18+
except Exception as e:
19+
errors.append({"Error in": "blank joke get", "Error": e})
20+
21+
"""Testing auth tokens"""
22+
try:
23+
j.get_joke(auth_token=token)
24+
except Exception as e:
25+
auth_token = None
26+
errors.append({"Error in": "auth usage", "Error": e})
27+
28+
"""Testing for errors in categories"""
29+
try:
30+
j.get_joke(category=["programming"], auth_token=token)
31+
except Exception as e:
32+
errors.append({"Error in": "category programming", "Error": e})
33+
try:
34+
j.get_joke(category=["misc"], auth_token=token)
35+
except Exception as e:
36+
errors.append({"Error in": "category miscellaneous", "Error": e})
37+
try:
38+
j.get_joke(category=["dark"], auth_token=token)
39+
except Exception as e:
40+
errors.append({"Error in": "category dark", "Error": e})
41+
42+
"""Testing for errors in blacklist"""
43+
try:
44+
j.get_joke(blacklist=["nsfw"], auth_token=token)
45+
except Exception as e:
46+
errors.append({"Error in": "blacklist nsfw", "Error": e})
47+
48+
try:
49+
j.get_joke(blacklist=["religious"], auth_token=token)
50+
except Exception as e:
51+
errors.append({"Error in": "blacklist religious", "Error": e})
52+
53+
try:
54+
j.get_joke(blacklist=["political"], auth_token=token)
55+
except Exception as e:
56+
errors.append({"Error in": "blacklist political", "Error": e})
57+
58+
try:
59+
j.get_joke(blacklist=["racist"], auth_token=token)
60+
except Exception as e:
61+
errors.append({"Error in": "blacklist political", "Error": e})
62+
63+
try:
64+
j.get_joke(blacklist=["sexist"], auth_token=token)
65+
except Exception as e:
66+
errors.append({"Error in": "blacklist sexist", "Error": e})
67+
68+
"""Testing for errors in response_format"""
69+
try:
70+
j.get_joke(response_format="xml", auth_token=token)
71+
except Exception as e:
72+
errors.append({"Error in": "response_format xml", "Error": e})
73+
74+
try:
75+
j.get_joke(response_format="yaml", auth_token=token)
76+
except Exception as e:
77+
errors.append({"Error in": "response_format yaml", "Error": e})
78+
79+
"""Testing for errors in type"""
80+
try:
81+
j.get_joke(joke_type="single", auth_token=token)
82+
except Exception as e:
83+
errors.append({"Error in": "type single", "Error": e})
84+
85+
try:
86+
j.get_joke(joke_type="twopart", auth_token=token)
87+
except Exception as e:
88+
errors.append({"Error in": "type double", "Error": e})
89+
90+
"""Testing for errors in search_string"""
91+
try:
92+
j.get_joke(search_string="search", auth_token=token)
93+
# as long as this gets a response, the api wrapper is fine;
94+
# it probably doesn't exist in a joke.
95+
except Exception as e:
96+
errors.append({"Error in": "search_string", "Error": e})
97+
98+
"""Testing for errors in id_range"""
99+
try:
100+
j.get_joke(id_range=[30, 151], auth_token=token)
101+
except Exception as e:
102+
errors.append({"Error in": "id_range", "Error": e})
103+
104+
if len(errors):
105+
for e in errors:
106+
print(f"Error in: {e['Error in']}\nError: {e['Error']}")
107+
if len(errors) == 1:
108+
raise Exception("1 error occured")
109+
110+
raise Exception(f"{len(errors)} errors occurred")

0 commit comments

Comments
 (0)