Skip to content

Commit

Permalink
refactor: split up the package screen structure (#62)
Browse files Browse the repository at this point in the history
  • Loading branch information
marcoceppi authored Mar 22, 2023
1 parent 8ed4232 commit 58cfb74
Show file tree
Hide file tree
Showing 13 changed files with 635 additions and 462 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: CI
on:
push:
branches:
- main
- main
pull_request:

jobs:
Expand All @@ -21,16 +21,16 @@ jobs:
version: 1.4.0
virtualenvs-create: true
virtualenvs-in-project: true
- name: System Deps
run: sudo apt install libgirepository1.0-dev libgtk-3-dev libadwaita-1-dev
- name: Cache Dependencies
id: cache-deps
uses: actions/cache@v3
with:
path: .venv
key: pydeps-${{ hashFiles('**/poetry.lock') }}
- name: Install Dependencies
run: |
sudo apt install libgirepository1.0-dev
poetry install --no-interaction --no-root
run: poetry install --no-interaction --no-root
if: steps.cache-deps.outputs.cache-hit != 'true'
- name: Install Project
run: poetry install --no-interaction
Expand Down
4 changes: 4 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ coverage = "^7.2.1"
pytest-cov = "^4.0.0"
pytest-asyncio = ">=0.20.3,<0.22.0"

[tool.isort]
profile = "black"
multi_line_output = 3

[build-system]
requires = ["poetry-core>=1.2.0"]
build-backend = "poetry.core.masonry.api"
89 changes: 89 additions & 0 deletions tests/test_screen_package_state.py
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"]
50 changes: 50 additions & 0 deletions tests/test_screen_package_utils.py
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)
Loading

0 comments on commit 58cfb74

Please sign in to comment.