Skip to content

Commit b073666

Browse files
authored
use github actions for ci (#9)
also add support for Python 3.9
1 parent 4b5a48c commit b073666

File tree

12 files changed

+172
-119
lines changed

12 files changed

+172
-119
lines changed

.github/workflows/main.yml

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
name: CI
2+
3+
# Controls when the action will run.
4+
on:
5+
# Triggers the workflow on push or pull request events
6+
push:
7+
pull_request:
8+
schedule:
9+
- cron: '0 12 * * 0' # run once a week on Sunday
10+
11+
# Allows you to run this workflow manually from the Actions tab
12+
workflow_dispatch:
13+
14+
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
15+
jobs:
16+
tests:
17+
name: "Python ${{ matrix.python-version }}"
18+
runs-on: "ubuntu-latest"
19+
20+
strategy:
21+
matrix:
22+
python-version: ["3.6", "3.7", "3.8", "3.9", "pypy3"]
23+
24+
# Steps represent a sequence of tasks that will be executed as part of the job
25+
steps:
26+
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
27+
- uses: "actions/checkout@v2"
28+
- uses: "actions/setup-python@v2"
29+
with:
30+
python-version: "${{ matrix.python-version }}"
31+
- name: "Install dependencies"
32+
run: |
33+
set -xe
34+
python -VV
35+
python -m site
36+
python -m pip install --upgrade pip setuptools wheel
37+
python -m pip install --upgrade virtualenv tox tox-gh-actions
38+
- name: "Run tox targets for ${{ matrix.python-version }}"
39+
run: "python -m tox"
40+
41+
- name: "Report to coveralls"
42+
# coverage is only created in the py39 environment
43+
# --service=github is a workaround for bug
44+
# https://github.com/coveralls-clients/coveralls-python/issues/251
45+
if: "matrix.python-version == '3.9'"
46+
run: |
47+
pip install coveralls
48+
coveralls --service=github
49+
env:
50+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.pre-commit-config.yaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
repos:
2+
- repo: https://github.com/psf/black
3+
rev: 20.8b1
4+
hooks:
5+
- id: black
6+
- repo: https://github.com/asottile/pyupgrade
7+
rev: v2.7.4
8+
hooks:
9+
- id: pyupgrade
10+
args: [--py36-plus]
11+
- repo: https://gitlab.com/pycqa/flake8
12+
rev: "3.8.4"
13+
hooks:
14+
- id: flake8

.travis.yml

Lines changed: 0 additions & 22 deletions
This file was deleted.

CHANGES.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ CHANGES
88

99
- Update supported Python versions.
1010

11+
- Use GitHub actions for CI.
1112

1213
0.1 (2016-07-01)
1314
================

morepath_reactredux/fakedb.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
class Zoo(object):
1+
class Zoo:
22
def __init__(self):
33
self.clear()
44

@@ -34,7 +34,7 @@ def get_all(self):
3434
return self._animals.values()
3535

3636

37-
class Animal(object):
37+
class Animal:
3838
def __init__(self, name, species):
3939
self.name = name
4040
self.species = species
@@ -45,10 +45,10 @@ def __init__(self, name, species):
4545

4646
def reset_zoo():
4747
zoo.clear()
48-
zoo.add(Animal('Bob', 'snake'))
49-
zoo.add(Animal('Fred', 'snake'))
50-
zoo.add(Animal('Anna', 'elephant'))
51-
zoo.add(Animal('Kate', 'tiger'))
48+
zoo.add(Animal("Bob", "snake"))
49+
zoo.add(Animal("Fred", "snake"))
50+
zoo.add(Animal("Anna", "elephant"))
51+
zoo.add(Animal("Kate", "tiger"))
5252

5353

5454
reset_zoo()

morepath_reactredux/model.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
class Root(object):
1+
class Root:
22
pass

morepath_reactredux/path.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,16 @@
33
from .model import Root
44

55

6-
@App.path(path='/', model=Root)
6+
@App.path(path="/", model=Root)
77
def get_root():
88
return Root()
99

1010

11-
@App.path(path='/animals', model=Zoo)
11+
@App.path(path="/animals", model=Zoo)
1212
def get_zoo():
1313
return zoo
1414

1515

16-
@App.path(path='/animals/{id}', model=Animal)
16+
@App.path(path="/animals/{id}", model=Animal)
1717
def get_animal(id=0):
1818
return zoo.get(id)

morepath_reactredux/run.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,22 @@
55
from .app import App
66

77

8-
def run(): # pragma: no cover
8+
def run(): # pragma: no cover
99
morepath.autoscan()
1010

11-
index = FileApp('static/index.html')
12-
static = DirectoryApp('static')
11+
index = FileApp("static/index.html")
12+
static = DirectoryApp("static")
1313
app = App()
1414

1515
@webob.dec.wsgify
1616
def morepath_with_static(request):
17-
if request.path_info_peek() == '':
17+
if request.path_info_peek() == "":
1818
return request.get_response(index)
1919

2020
popped = request.path_info_pop()
21-
if popped == 'api':
21+
if popped == "api":
2222
return request.get_response(app)
23-
elif popped == 'static':
23+
elif popped == "static":
2424
return request.get_response(static)
2525

2626
raise HTTPNotFound()

morepath_reactredux/tests/test_rest.py

Lines changed: 41 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -18,65 +18,73 @@ def teardown_function(function):
1818
def test_root():
1919
c = Client(App())
2020

21-
response = c.get('/')
21+
response = c.get("/")
2222
assert response.json == {"collection": "http://localhost/animals"}
2323

2424

2525
def test_zoo():
2626
c = Client(App())
27-
response = c.get('/animals')
28-
zoo = {"animals": [
29-
{"@id": "http://localhost/animals/0",
30-
"name": "Bob", "species": "snake"},
31-
{"@id": "http://localhost/animals/1",
32-
"name": "Fred", "species": "snake"},
33-
{"@id": "http://localhost/animals/2",
34-
"name": "Anna", "species": "elephant"},
35-
{"@id": "http://localhost/animals/3",
36-
"name": "Kate", "species": "tiger"}
37-
]}
27+
response = c.get("/animals")
28+
zoo = {
29+
"animals": [
30+
{"@id": "http://localhost/animals/0", "name": "Bob", "species": "snake"},
31+
{"@id": "http://localhost/animals/1", "name": "Fred", "species": "snake"},
32+
{
33+
"@id": "http://localhost/animals/2",
34+
"name": "Anna",
35+
"species": "elephant",
36+
},
37+
{"@id": "http://localhost/animals/3", "name": "Kate", "species": "tiger"},
38+
]
39+
}
3840
assert response.json == zoo
3941

4042

4143
def test_animal():
4244
c = Client(App())
43-
response = c.get('/animals/0')
44-
assert response.json == {"@id": "http://localhost/animals/0",
45-
"name": "Bob", "species": "snake"}
45+
response = c.get("/animals/0")
46+
assert response.json == {
47+
"@id": "http://localhost/animals/0",
48+
"name": "Bob",
49+
"species": "snake",
50+
}
4651

4752

4853
def test_add_animal():
4954
c = Client(App())
5055

5156
new_animal_json = json.dumps({"name": "Lupus", "species": "wolf"})
52-
response = c.post('/animals', new_animal_json)
53-
new_animal_response = {"@id": "http://localhost/animals/4",
54-
"name": "Lupus", "species": "wolf"}
57+
response = c.post("/animals", new_animal_json)
58+
new_animal_response = {
59+
"@id": "http://localhost/animals/4",
60+
"name": "Lupus",
61+
"species": "wolf",
62+
}
5563
assert response.json == new_animal_response
5664

5765

5866
def test_delete_animal():
5967
c = Client(App())
6068

61-
response = c.delete('/animals/2')
62-
zoo = {"animals": [
63-
{"@id": "http://localhost/animals/0",
64-
"name": "Bob", "species": "snake"},
65-
{"@id": "http://localhost/animals/1",
66-
"name": "Fred", "species": "snake"},
67-
{"@id": "http://localhost/animals/3",
68-
"name": "Kate", "species": "tiger"}
69-
]}
69+
response = c.delete("/animals/2")
70+
zoo = {
71+
"animals": [
72+
{"@id": "http://localhost/animals/0", "name": "Bob", "species": "snake"},
73+
{"@id": "http://localhost/animals/1", "name": "Fred", "species": "snake"},
74+
{"@id": "http://localhost/animals/3", "name": "Kate", "species": "tiger"},
75+
]
76+
}
7077
assert response.json == zoo
7178

7279

7380
def test_change_animal():
7481
c = Client(App())
7582

76-
changed_animal_json = json.dumps(
77-
{"name": "Changed Fred", "species": "fish"}
78-
)
79-
response = c.put('/animals/1', changed_animal_json)
80-
changed_animal_response = {"@id": "http://localhost/animals/1",
81-
"name": "Changed Fred", "species": "fish"}
83+
changed_animal_json = json.dumps({"name": "Changed Fred", "species": "fish"})
84+
response = c.put("/animals/1", changed_animal_json)
85+
changed_animal_response = {
86+
"@id": "http://localhost/animals/1",
87+
"name": "Changed Fred",
88+
"species": "fish",
89+
}
8290
assert response.json == changed_animal_response

morepath_reactredux/view.py

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,18 @@
55

66
@App.json(model=Root)
77
def root_get(self, request):
8-
return {
9-
'collection': request.link(zoo)
10-
}
8+
return {"collection": request.link(zoo)}
119

1210

1311
@App.json(model=Zoo)
1412
def zoo_get(self, request):
15-
return {
16-
'animals': [request.view(animal) for animal in self.get_all()]
17-
}
13+
return {"animals": [request.view(animal) for animal in self.get_all()]}
1814

1915

20-
@App.json(model=Zoo, request_method='POST')
16+
@App.json(model=Zoo, request_method="POST")
2117
def zoo_post(self, request):
2218
animal_json = request.json
23-
animal = Animal(animal_json['name'], animal_json['species'])
19+
animal = Animal(animal_json["name"], animal_json["species"])
2420
self.add(animal)
2521

2622
@request.after
@@ -32,22 +28,18 @@ def after(response):
3228

3329
@App.json(model=Animal)
3430
def animal_get(self, request):
35-
return {
36-
'@id': request.link(self),
37-
'name': self.name,
38-
'species': self.species
39-
}
31+
return {"@id": request.link(self), "name": self.name, "species": self.species}
4032

4133

42-
@App.json(model=Animal, request_method='PUT')
34+
@App.json(model=Animal, request_method="PUT")
4335
def animal_put(self, request):
4436
animal_json = request.json
45-
self.name = animal_json['name']
46-
self.species = animal_json['species']
37+
self.name = animal_json["name"]
38+
self.species = animal_json["species"]
4739
return request.view(self)
4840

4941

50-
@App.json(model=Animal, request_method='DELETE')
42+
@App.json(model=Animal, request_method="DELETE")
5143
def animal_delete(self, request):
5244
zoo.remove(self.id)
5345
return request.view(zoo)

0 commit comments

Comments
 (0)