Skip to content
This repository has been archived by the owner on May 17, 2019. It is now read-only.

Commit

Permalink
Preserve props order
Browse files Browse the repository at this point in the history
  • Loading branch information
Marica Odagaki committed Nov 4, 2016
1 parent ff19195 commit 126025c
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 16 deletions.
2 changes: 1 addition & 1 deletion elm_deps_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def sync_versions(top_level_file, spec_file, quiet=False, dry=False, note_test_d
top_level = json.load(f)

with open(spec_file) as f:
spec = json.load(f)
spec = json.load(f, object_pairs_hook=OrderedDict)

messages = []

Expand Down
64 changes: 49 additions & 15 deletions tests/test_elm_deps_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,55 @@
import json

import pytest
from hypothesis import given
import hypothesis.strategies as st

import elm_deps_sync


def test_spec_order_is_preserved(tmpdir):
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 = {
'dependencies': OrderedDict([
('NoRedInk/top-3', '1.0.0 <= v <= 1.0.0'),
('NoRedInk/top-1', '1.0.0 <= v <= 1.0.0'),
('NoRedInk/top-2', '1.0.0 <= v <= 1.0.0'),
])
}
top_level = _make_package(top_level_keys, top_level_deps)
top_level_file.write(json.dumps(top_level))

spec = {
'dependencies': OrderedDict([
('NoRedInk/top-2', '1.0.0 <= v <= 1.0.0'),
('NoRedInk/top-1', '1.0.0 <= v <= 1.0.0'),
])
}
spec = _make_package(spec_keys, spec_deps)
spec_file.write(json.dumps(spec))

elm_deps_sync.sync_versions(
Expand All @@ -35,4 +61,12 @@ def test_spec_order_is_preserved(tmpdir):
note_test_deps=True)

new_spec = json.loads(spec_file.read(), object_pairs_hook=OrderedDict)
assert new_spec['dependencies'].keys() == ['NoRedInk/top-1', 'NoRedInk/top-2', 'NoRedInk/top-3']
assert new_spec.keys() == spec_keys + ['test-dependencies']
assert new_spec['dependencies'].keys() == ['NoRedInk/spec-1', 'NoRedInk/spec-2', 'NoRedInk/top-1', 'NoRedInk/top-2', 'NoRedInk/top-3']
assert 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

0 comments on commit 126025c

Please sign in to comment.