This repository has been archived by the owner on May 17, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #16 from NoRedInk/no-surprising-diffs
elm_deps_sync: avoid unwanted diffs
- Loading branch information
Showing
4 changed files
with
102 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
language: python | ||
cache: pip | ||
python: | ||
# see https://docs.travis-ci.com/user/languages/python/ for options | ||
- "2.7" # hypothesis's minimum version for 2.x | ||
- "3.3" # hypothesis's minimum version for 3.x | ||
- "3.4" # trusty | ||
- "3.5" # >= xenial | ||
- "3.6-dev" | ||
- "nightly" | ||
# command to install dependencies | ||
install: | ||
- "pip install -r dev-requirements.txt" | ||
# command to run tests | ||
script: | ||
- "python -m pytest tests/ -v" | ||
notifications: | ||
email: false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
enum34==1.1.6 | ||
hypothesis==3.6.0 | ||
py==1.4.31 | ||
pytest==3.0.3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
from collections import OrderedDict | ||
import json | ||
|
||
import pytest | ||
from hypothesis import given | ||
import hypothesis.strategies as st | ||
|
||
import elm_deps_sync | ||
|
||
|
||
package_skeleton = { | ||
"version": "1.0.0", | ||
"summary": "test elm deps sync", | ||
"repository": "https://github.com/NoRedInk/elm-ops-tooling", | ||
"license": "BSD-3", | ||
"source-directories": ".", | ||
"exposed-modules": [], | ||
"native-modules": True, | ||
"dependencies": {}, | ||
"elm-version": "0.17.0 <= v <= 0.17.0", | ||
} | ||
|
||
top_level_deps = [ | ||
('NoRedInk/top-1', '1.0.0 <= v <= 1.0.0'), | ||
('NoRedInk/top-2', '1.0.0 <= v <= 1.0.0'), | ||
('NoRedInk/top-3', '1.0.0 <= v <= 1.0.0'), | ||
] | ||
|
||
spec_deps = [ | ||
('NoRedInk/top-1', '1.0.0 <= v <= 1.0.0'), | ||
('NoRedInk/top-2', '1.0.0 <= v <= 1.0.0'), | ||
('NoRedInk/spec-1', '1.0.0 <= v <= 1.0.0'), | ||
('NoRedInk/spec-2', '1.0.0 <= v <= 1.0.0'), | ||
] | ||
|
||
|
||
@given(top_level_keys=st.permutations(package_skeleton.keys()), | ||
top_level_deps=st.permutations(top_level_deps), | ||
spec_keys=st.permutations(package_skeleton.keys()), | ||
spec_deps=st.permutations(spec_deps)) | ||
def test_spec_order_is_preserved( | ||
tmpdir, | ||
top_level_keys, | ||
top_level_deps, | ||
spec_keys, | ||
spec_deps): | ||
top_level_file = tmpdir.join('elm-package.json') | ||
spec_file = tmpdir.join('spec-elm-package.json') | ||
|
||
top_level = _make_package(top_level_keys, top_level_deps) | ||
top_level_file.write(json.dumps(top_level)) | ||
|
||
spec = _make_package(spec_keys, spec_deps) | ||
spec_file.write(json.dumps(spec)) | ||
|
||
elm_deps_sync.sync_versions( | ||
str(top_level_file), | ||
str(spec_file), | ||
quiet=False, | ||
dry=False, | ||
note_test_deps=True) | ||
|
||
new_spec = json.loads(spec_file.read(), object_pairs_hook=OrderedDict) | ||
assert list(new_spec.keys()) == spec_keys + ['test-dependencies'] | ||
assert list(new_spec['dependencies'].keys()) == ['NoRedInk/spec-1', 'NoRedInk/spec-2', 'NoRedInk/top-1', 'NoRedInk/top-2', 'NoRedInk/top-3'] | ||
assert list(new_spec['test-dependencies'].keys()) == ['NoRedInk/spec-1', 'NoRedInk/spec-2'] | ||
|
||
|
||
def _make_package(keys, deps): | ||
package = OrderedDict((key, package_skeleton[key]) for key in keys) | ||
package['dependencies'] = OrderedDict(deps) | ||
return package |