-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: split up the package screen structure (#62)
- Loading branch information
1 parent
8ed4232
commit 58cfb74
Showing
13 changed files
with
635 additions
and
462 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
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,89 @@ | ||
import pytest | ||
from yafti.screen.package.state import PackageScreenState | ||
from pydantic import ValidationError | ||
|
||
|
||
def test_state_set(): | ||
state = PackageScreenState() | ||
state.set("hello", True) | ||
assert state.get("hello") is True | ||
|
||
|
||
def test_state_set_fail(): | ||
state = PackageScreenState() | ||
with pytest.raises(ValidationError): | ||
state.set("hello", "world") | ||
|
||
|
||
def test_state_load(): | ||
input = {"hello": True, "world": False} | ||
state = PackageScreenState() | ||
state.load(input) | ||
assert state.get("hello") is True | ||
assert state.get("world") is False | ||
|
||
|
||
def test_state_from_dict(): | ||
input = {"hello": True, "world": False} | ||
state = PackageScreenState.from_dict(input) | ||
assert state.get("hello") is True | ||
assert state.get("world") is False | ||
|
||
|
||
def test_state_remove(): | ||
state = PackageScreenState() | ||
state.set("kenobi", False) | ||
state.set("general", True) | ||
assert state.get("kenobi") is False | ||
assert state.get("general") is True | ||
state.remove("kenobi") | ||
assert state.get("kenobi") is None | ||
assert state.get("general") is True | ||
|
||
|
||
def test_state_on_off(): | ||
state = PackageScreenState() | ||
state.on("grievous") | ||
assert state.get("grievous") is True | ||
state.off("grievous") | ||
assert state.get("grievous") is False | ||
|
||
state.off("ani") | ||
assert state.get("ani") is False | ||
state.on("ani") | ||
assert state.get("ani") is True | ||
|
||
|
||
def test_state_toggle(): | ||
state = PackageScreenState() | ||
state.on("chewy") | ||
assert state.get("chewy") is True | ||
state.toggle("chewy") | ||
assert state.get("chewy") is False | ||
state.toggle("chewy") | ||
assert state.get("chewy") is True | ||
|
||
|
||
def test_state_toggle_error(): | ||
state = PackageScreenState() | ||
with pytest.raises(KeyError): | ||
state.toggle("barf") | ||
|
||
|
||
def test_state_get_on(): | ||
state = PackageScreenState() | ||
state.on("chewy") | ||
state.on("han") | ||
state.off("greedo") | ||
|
||
assert state.get_on() == ["chewy", "han"] | ||
assert state.get_on("ch") == ["chewy"] | ||
|
||
|
||
def test_state_keys(): | ||
state = PackageScreenState() | ||
state.on("AA") | ||
state.on("BB") | ||
state.off("CC") | ||
|
||
assert state.keys() == ["AA", "BB", "CC"] |
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,50 @@ | ||
from yafti.screen.package.utils import parse_packages | ||
|
||
|
||
def test_parse_packages_groups(): | ||
cfg = { | ||
"Core": { | ||
"description": "hello world", | ||
"packages": [ | ||
{"Calculator": "org.gnome.Calculator"}, | ||
{"Firefox": "org.mozilla.firefox"}, | ||
], | ||
}, | ||
"Gaming": { | ||
"description": "hello games", | ||
"default": False, | ||
"packages": [ | ||
{"Steam": "com.valvesoftware.Steam"}, | ||
{"Games": "org.gnome.Games"}, | ||
], | ||
}, | ||
} | ||
|
||
expected = { | ||
"group:Core": True, | ||
"pkg:org.gnome.Calculator": True, | ||
"pkg:org.mozilla.firefox": True, | ||
"group:Gaming": True, | ||
"pkg:com.valvesoftware.Steam": True, | ||
"pkg:org.gnome.Games": True, | ||
} | ||
|
||
assert expected == parse_packages(cfg) | ||
|
||
|
||
def test_parse_packages_list(): | ||
cfg = [ | ||
{"Calculator": "org.gnome.Calculator"}, | ||
{"Firefox": "org.mozilla.firefox"}, | ||
{"Steam": "com.valvesoftware.Steam"}, | ||
{"Games": "org.gnome.Games"}, | ||
] | ||
|
||
expected = { | ||
"pkg:org.gnome.Calculator": True, | ||
"pkg:org.mozilla.firefox": True, | ||
"pkg:com.valvesoftware.Steam": True, | ||
"pkg:org.gnome.Games": True, | ||
} | ||
|
||
assert expected == parse_packages(cfg) |
Oops, something went wrong.