Skip to content

Enhance alphabetic sorting and place deprecated platform at the bottom #1278

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
May 7, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
updated tests
  • Loading branch information
umbynos committed May 6, 2021
commit 7a89db1ca7515f6aee86f7b6af8661c5701a6568
78 changes: 78 additions & 0 deletions test/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -530,3 +530,81 @@ def test_core_search_update_index_delay(run_command, data_dir):
res = run_command("core search")
assert res.ok
assert "Updating index" not in res.stdout


def test_core_search_sorted_results(run_command, httpserver):
# Set up the server to serve our custom index file
test_index = Path(__file__).parent / "testdata" / "test_index.json"
httpserver.expect_request("/test_index.json").respond_with_data(test_index.read_text())

# update custom index
url = httpserver.url_for("/test_index.json")
assert run_command(f"core update-index --additional-urls={url}")

# list all with additional url specified
result = run_command(f"core search --additional-urls={url}")
assert result.ok

lines = [l.strip().split(maxsplit=2) for l in result.stdout.strip().splitlines()][1:]
not_deprecated = [l for l in lines if not l[2].startsWith("[DEPRECATED]")]
deprecated = [l for l in lines if l[2].startsWith("[DEPRECATED]")]

# verify that results are already sorted correctly
assert not_deprecated == sorted(not_deprecated, key=lambda tokens: tokens[2])
assert deprecated == sorted(deprecated, key=lambda tokens: tokens[2])

# verify that deprecated platforms are the last ones
assert lines == deprecated + not_deprecated

# test same behaviour with json output
result = run_command(f"core search --additional-urls={url} --format=json")
assert result.ok

platforms = json.loads(result.stdout)
not_deprecated = [p for p in platforms if not p.get("deprecated")]
deprecated = [p for p in platforms if p.get("deprecated")]

# verify that results are already sorted correctly
assert not_deprecated == sorted(not_deprecated, key=lambda keys: keys["name"])
assert deprecated == sorted(deprecated, key=lambda keys: keys["name"])
# verify that deprecated platforms are the last ones
assert platforms == deprecated + not_deprecated


def test_core_list_sorted_results(run_command, httpserver):
# Set up the server to serve our custom index file
test_index = Path(__file__).parent / "testdata" / "test_index.json"
httpserver.expect_request("/test_index.json").respond_with_data(test_index.read_text())

# update custom index
url = httpserver.url_for("/test_index.json")
assert run_command(f"core update-index --additional-urls={url}")

# list all with additional url specified
result = run_command(f"core list --additional-urls={url}")
assert result.ok

lines = [l.strip().split(maxsplit=3) for l in result.stdout.strip().splitlines()][1:]
not_deprecated = [l for l in lines if not l[3].startsWith("[DEPRECATED]")]
deprecated = [l for l in lines if l[3].startsWith("[DEPRECATED]")]

# verify that results are already sorted correctly
assert not_deprecated == sorted(not_deprecated, key=lambda tokens: tokens[3])
assert deprecated == sorted(deprecated, key=lambda tokens: tokens[3])

# verify that deprecated platforms are the last ones
assert lines == deprecated + not_deprecated

# test same behaviour with json output
result = run_command(f"core list --additional-urls={url} --format=json")
assert result.ok

platforms = json.loads(result.stdout)
not_deprecated = [p for p in platforms if not p.get("deprecated")]
deprecated = [p for p in platforms if p.get("deprecated")]

# verify that results are already sorted correctly
assert not_deprecated == sorted(not_deprecated, key=lambda keys: keys["name"])
assert deprecated == sorted(deprecated, key=lambda keys: keys["name"])
# verify that deprecated platforms are the last ones
assert platforms == deprecated + not_deprecated
1 change: 1 addition & 0 deletions test/testdata/test_index.json
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@
"checksum": "SHA-256:6a338cf4d6d501176a2d352c87a8d72ac7488b8c5b82cdf2a4e2cef630391092",
"name": "Platform",
"version": "1.2.3",
"deprecated": true,
"architecture": "x86",
"archiveFileName": "core.zip",
"size": "486",
Expand Down