Skip to content

Commit

Permalink
Overhaul build step
Browse files Browse the repository at this point in the history
  • Loading branch information
Zac-HD committed Feb 14, 2019
1 parent 0ccdb12 commit b5ca398
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 65 deletions.
2 changes: 2 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[flake8]
ignore = D,E501,W503
8 changes: 8 additions & 0 deletions .isort.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[settings]
known_third_party = hypothesis, jsonschema
known_first_party = hypothesis_jsonschema
multi_line_output = 3
include_trailing_comma = True
force_grid_wrap = 0
combine_as_imports = True
line_length = 88
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ install:
- pip install -r requirements.txt
- pip install .
script:
- pytest
- source check.sh
- git diff --exit-code
deploy:
provider: script
script: python setup.py sdist && twine upload --skip-existing dist/*
Expand Down
4 changes: 4 additions & 0 deletions check.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
black .
isort -rc -y .
flake8
pytest
3 changes: 2 additions & 1 deletion requirements.in
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ hypothesis
jsonschema

black
pylint
flake8
isort
pytest
pytest-cov
pytest-mypy
18 changes: 9 additions & 9 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,28 @@
# pip-compile --output-file requirements.txt requirements.in
#
appdirs==1.4.3 # via black
astroid==2.1.0 # via pylint
atomicwrites==1.3.0 # via pytest
attrs==18.2.0 # via black, hypothesis, pytest
black==18.9b0
click==7.0 # via black
colorama==0.4.1 # via pylint, pytest
colorama==0.4.1 # via pytest
coverage==4.5.2 # via pytest-cov
entrypoints==0.3 # via flake8
flake8==3.7.5
hypothesis==4.5.4
isort==4.3.4 # via pylint
isort==4.3.4
jsonschema==2.6.0
lazy-object-proxy==1.3.1 # via astroid
mccabe==0.6.1 # via pylint
mccabe==0.6.1 # via flake8
more-itertools==5.0.0 # via pytest
mypy-extensions==0.4.1 # via mypy
mypy==0.660 # via pytest-mypy
pluggy==0.8.1 # via pytest
py==1.7.0 # via pytest
pylint==2.2.2
pycodestyle==2.5.0 # via flake8
pyflakes==2.1.0 # via flake8
pytest-cov==2.6.1
pytest-mypy==0.3.2
pytest==4.2.0
six==1.12.0 # via astroid, more-itertools, pytest
six==1.12.0 # via more-itertools, pytest
toml==0.10.0 # via black
typed-ast==1.2.0 # via astroid, mypy
wrapt==1.11.1 # via astroid
typed-ast==1.2.0 # via mypy
4 changes: 2 additions & 2 deletions src/hypothesis_jsonschema/_impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
import re
from typing import Any, Dict, List, Union

import hypothesis.provisional as prov
import hypothesis.strategies as st
import jsonschema
from hypothesis import assume
import hypothesis.strategies as st
import hypothesis.provisional as prov
from hypothesis.errors import InvalidArgument

# Mypy does not (yet!) support recursive type definitions.
Expand Down
67 changes: 15 additions & 52 deletions test_hypothesis_jsonschema.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,54 +2,23 @@
# pylint: disable=no-value-for-parameter,wrong-import-order

import json
import os
import subprocess

from hypothesis import given, settings, HealthCheck
import hypothesis.strategies as st
import jsonschema
import pytest
from hypothesis import HealthCheck, given, settings

from hypothesis_jsonschema import from_schema, json_schemata
from hypothesis_jsonschema._impl import (
JSON_STRATEGY,
encode_canonical_json,
gen_number,
gen_string,
gen_array,
gen_number,
gen_object,
gen_string,
)


def files_to_check():
"""Return a list of all .py files in the repo."""
files = []
for dirpath, _, fnames in os.walk("."):
files.extend(os.path.join(dirpath, f) for f in fnames if f.endswith(".py"))
assert len(files) >= 3
return files


def test_all_py_files_are_blackened():
"""Check that all .py files are formatted with Black."""
subprocess.run(
["black", "--py36", "--check"] + files_to_check(),
check=True,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
)


def test_pylint_passes():
"""Check that pylint passes on all .py files."""
subprocess.run(
["pylint"] + files_to_check(),
check=True,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
)


@given(JSON_STRATEGY)
def test_canonical_json_encoding(v):
"""Test our hand-rolled canonicaljson implementation."""
Expand All @@ -59,25 +28,19 @@ def test_canonical_json_encoding(v):
assert encode_canonical_json(v2) == encoded


schema_strategies = [
gen_number("integer"),
gen_number("number"),
gen_string(),
gen_array(),
gen_object(),
json_schemata(),
]
for s in schema_strategies:
s.validate()


@settings(
max_examples=200,
suppress_health_check=[HealthCheck.too_slow],
deadline=100, # maximum milliseconds per test case
)
@settings(max_examples=200, suppress_health_check=[HealthCheck.too_slow], deadline=None)
@given(data=st.data())
@pytest.mark.parametrize("schema_strategy", schema_strategies)
@pytest.mark.parametrize(
"schema_strategy",
[
gen_number("integer"),
gen_number("number"),
gen_string(),
gen_array(),
gen_object(),
json_schemata(),
],
)
def test_generated_data_matches_schema(schema_strategy, data):
"""Check that an object drawn from an arbitrary schema is valid."""
schema = data.draw(schema_strategy)
Expand Down

0 comments on commit b5ca398

Please sign in to comment.