Skip to content

Commit

Permalink
Merge branch 'update'
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthieu Berthomé committed Sep 27, 2020
2 parents 7edf0f3 + 5800550 commit bd4d8eb
Show file tree
Hide file tree
Showing 9 changed files with 97 additions and 46 deletions.
34 changes: 6 additions & 28 deletions .github/workflows/python-package.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ jobs:

steps:
- uses: actions/checkout@v1
- uses: actions/setup-python@v2
with:
python-version: 3.8
- name: Install dependencies
run: |
pip install -r dev-requirements.txt
Expand All @@ -24,39 +27,14 @@ jobs:
name: code
path: rebrickable/api

test-3-8:
needs: generate-code

runs-on: ubuntu-latest
container: python:3.8.0

steps:
- uses: actions/checkout@v1
- name: Download generated code
uses: actions/download-artifact@v1
with:
name: code
path: rebrickable/api
- name: Install dependencies
run: |
pip install -r dev-requirements.txt
- name: Test
run: |
tox
- name: Coveralls
env:
COVERALLS_REPO_TOKEN: ${{ secrets.coveralls_repo_token }}
run: |
coveralls
test:
needs: generate-code

runs-on: ubuntu-latest
strategy:
max-parallel: 4
matrix:
python-version: [2.7, 3.5, 3.6, 3.7]
python-version: [3.5, 3.6, 3.7]

steps:
- uses: actions/checkout@v1
Expand Down Expand Up @@ -128,7 +106,7 @@ jobs:
strategy:
max-parallel: 4
matrix:
python-version: [2.7, 3.5]
python-version: [3.5]

steps:
- uses: actions/checkout@v1
Expand All @@ -150,7 +128,7 @@ jobs:
run: |
pip install -r dev-requirements.txt
- name: Build package sdist
if: matrix.python-version == '2.7'
if: matrix.python-version == '3.5'
run: |
python setup.py sdist
- name: Build package wheel
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,5 @@ api-yaml/
Pipfile.lock

docs/reference/rebrickable/

coverage_html/
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ TAG_NAME:=${TAG_NAME}
VERSION ?= $(if $(TAG_NAME),$(TAG_NAME),dev)

swagger.json: rebrickable.json patch_swagger.py
python patch_swagger.py
python3 patch_swagger.py
echo -- `cat swagger.json`

clean:
Expand Down
2 changes: 2 additions & 0 deletions dev-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,5 @@ tox-pyenv
tox-gh-actions
-r requirements.txt
wheel
docstring-parser
pathlib
2 changes: 2 additions & 0 deletions patch_swagger.py
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ def get_typedef_array(cls):
"type": "object",
"properties": {
"count": Integer,
'next': String,
'previous': String,
"results": {
"type": "array",
"items": {
Expand Down
1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
decorator
appdirs
enum34
PyYaml
click >=6
urllib3 >= 1.15
Expand Down
48 changes: 48 additions & 0 deletions tests/cli/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@

def parse_docstring(docstring):
"""Parse the docstring into its components.
:returns: a dictionary of form
{
"short_description": ...,
"long_description": ...,
"params": [{"name": ..., "doc": ...}, ...],
"returns": ...
}
"""

short_description = long_description = returns = ""
params = []

if docstring:
docstring = trim(docstring)

lines = docstring.split("\n", 1)
short_description = lines[0]

if len(lines) > 1:
long_description = lines[1].strip()

params_returns_desc = None

match = PARAM_OR_RETURNS_REGEX.search(long_description)
if match:
long_desc_end = match.start()
params_returns_desc = long_description[long_desc_end:].strip()
long_description = long_description[:long_desc_end].rstrip()

if params_returns_desc:
params = [
{"name": name, "doc": trim(doc)}
for name, doc in PARAM_REGEX.findall(params_returns_desc)
]

match = RETURNS_REGEX.search(params_returns_desc)
if match:
returns = reindent(match.group("doc"))

return {
"short_description": short_description,
"long_description": long_description,
"params": params,
"returns": returns
}
48 changes: 35 additions & 13 deletions tests/cli/test_models_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
import six
from jsondiff import diff

import rebrickable
from rebrickable.api import LegoApi, UsersApi
from docstring_parser import parse
from rebrickable.cli.common import State
from rebrickable.cli.utils import get_api_client, get_user_token

Expand Down Expand Up @@ -44,15 +46,24 @@ def remove_nulls(d):

@pytest.mark.parametrize(['func', 'kwargs'], [
('lego_colors_read', dict(id=7)),
('lego_colors_list', dict()),
('lego_elements_read', dict(element_id=4245295)),
('lego_mocs_read', dict(set_num='MOC-5634')),
('lego_part_categories_read', dict(id=42)),
('lego_part_categories_list', dict()),
('lego_parts_colors_read', dict(color_id=4, part_num='3004')),
('lego_parts_colors_list', dict(part_num='3004')),
('lego_parts_colors_sets_list', dict(color_id=4, part_num='3004')),
('lego_parts_read', dict(part_num='3004')),
('lego_parts_list', dict()),
('lego_parts_read', dict(part_num='4070')),
('lego_sets_alternates_list', dict(set_num='75192-1')),
('lego_sets_read', dict(set_num='75192-1')),
('lego_sets_read', dict(set_num='31027-1')),
('lego_sets_list', dict()),
('lego_sets_parts_list', dict(set_num='75192-1')),
('lego_sets_sets_list', dict(set_num='75192-1')),
('lego_themes_read', dict(id=99)),
('lego_themes_list', dict()),
], ids=get_id)
@pytest.mark.integration
def test_lego_objects_attributes(func, kwargs, lego_api, users_context):
Expand All @@ -62,10 +73,11 @@ def test_lego_objects_attributes(func, kwargs, lego_api, users_context):

@pytest.mark.parametrize(['func', 'kwargs'], [
('users_build_read', dict(set_num='75192-1')),
('users_partlists_parts_read', dict(list_id=40476, color_id=1, part_num='3298p61')), # user partlist 40476 part 1 3298p61
('users_partlists_read', dict(list_id=40476)),
('users_setlists_read', dict(list_id=221643)),
('users_sets_read', dict(set_num='8277-1')),
('users_partlists_parts_read', dict(list_id=229534, color_id=6, part_num='11110')),
# user partlist 40476 part 1 3298p61
('users_partlists_read', dict(list_id=229534)),
('users_setlists_read', dict(list_id=462364)),
('users_sets_read', dict(set_num='7195-1')),
], ids=get_id)
@pytest.mark.integration
def test_objects_attributes(func, kwargs, users_context):
Expand All @@ -80,16 +92,26 @@ def test_users_badges_read_attributes(users_context):


def do_test(func, kwargs, state):
obj = state.client.sanitize_for_serialization(func(**kwargs))
# converted from API
d = parse(func.__doc__)
type_name = d.returns.description.splitlines()[0]
klass = getattr(rebrickable.api.models, type_name)
obj = state.client._ApiClient__deserialize_model(state.client.sanitize_for_serialization(func(**kwargs)), klass)
# raw from API
obj_no_preload = json.loads(func(_preload_content=False, **kwargs).data)

# ignore Set last_modified_dt (datetime format)
if 'last_modified_dt' in obj:
obj['last_modified_dt'] = obj_no_preload['last_modified_dt']
if 'set' in obj:
obj['set']['last_modified_dt'] = obj_no_preload['set']['last_modified_dt']
def dict_equal(expected, actual):
for k, v in actual.items():
if v is None and k not in expected:
# kinda nullable
continue
if isinstance(v, dict):
dict_equal(expected[k], v)
else:
assert expected[k] == v

ddiff = diff(obj_no_preload, obj)
#dict_equal(obj.to_dict(), obj_no_preload)

ddiff = diff(obj_no_preload, obj, syntax='explicit')

pprint(ddiff)
assert ddiff == {}
4 changes: 1 addition & 3 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
[tox]
envlist = py27, py35, py36, py37, py38

envlist = py35, py36, py37, py38

[gh-actions]
python =
2.7: py27
3.5: py35
3.6: py36
3.7: py37
Expand Down

0 comments on commit bd4d8eb

Please sign in to comment.