mirror of
https://github.com/aclist/dztui.git
synced 2026-10-31 15:12:48 +01:00
fix: rewrite tests
This commit is contained in:
1 parent
156c1f8ec4
commit
8fc7aa5165
3 files changed
+33
-11
No files matched your search
@@ -438,6 +438,10 @@ def get_app_path(folders_path: Path, appid: int) -> Path:
|
|||||||
raise AppNotInstalledError(
|
raise AppNotInstalledError(
|
||||||
f"Failed to find a libraryfolder for the appid {appid}"
|
f"Failed to find a libraryfolder for the appid {appid}"
|
||||||
)
|
)
|
||||||
|
if Path(app_path).exists() is False:
|
||||||
|
raise AppMovedError(
|
||||||
|
f"The location '{app_path}' pointed to by '{appid}' no longer exists and may have been changed on the disk."
|
||||||
|
)
|
||||||
|
|
||||||
return Path(app_path)
|
return Path(app_path)
|
||||||
|
|
||||||
|
|||||||
+14
-2
@@ -1,5 +1,17 @@
|
|||||||
def test_headings():
|
import pytest
|
||||||
with open("CHANGELOG.md", "r") as f:
|
|
||||||
|
from importlib import resources
|
||||||
|
from dzgui.const.constants import APP_NAME_LOWER, CHANGELOG_PATH
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def changelog():
|
||||||
|
path = resources.files(APP_NAME_LOWER).joinpath(CHANGELOG_PATH)
|
||||||
|
return path
|
||||||
|
|
||||||
|
|
||||||
|
def test_headings(changelog):
|
||||||
|
with open(changelog, "r") as f:
|
||||||
lines = f.readlines()
|
lines = f.readlines()
|
||||||
for line in lines:
|
for line in lines:
|
||||||
if line.startswith("#"):
|
if line.startswith("#"):
|
||||||
|
|||||||
+15
-9
@@ -2,13 +2,14 @@ import pytest
|
|||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
import dzgui.api.pefile as PeFile
|
import dzgui.api.pefile as PeFile
|
||||||
from dzgui.api.pefile import (VDFLoadError, AppNotInstalledError, AppMovedError)
|
from dzgui.api.pefile import VDFLoadError, AppNotInstalledError, AppMovedError
|
||||||
|
|
||||||
from dzgui.config.query import get_config
|
from dzgui.config.query import get_config
|
||||||
from dzgui.config.xdg import get_xdg_paths, parse_filepaths
|
from dzgui.config.xdg import get_xdg_paths, parse_filepaths
|
||||||
from dzgui.const.constants import APPID_DAYZ
|
from dzgui.const.constants import APPID_DAYZ
|
||||||
|
|
||||||
from tests.fixtures import fixture_path
|
from tests.fixtures import fixture_path
|
||||||
|
|
||||||
pytestmark = pytest.mark.pefile
|
pytestmark = pytest.mark.pefile
|
||||||
|
|
||||||
|
|
||||||
@@ -16,6 +17,7 @@ pytestmark = pytest.mark.pefile
|
|||||||
def second_drive():
|
def second_drive():
|
||||||
return fixture_path("in_library_on_second_drive.vdf")
|
return fixture_path("in_library_on_second_drive.vdf")
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def default_steam_path():
|
def default_steam_path():
|
||||||
paths = get_xdg_paths()
|
paths = get_xdg_paths()
|
||||||
@@ -23,17 +25,17 @@ def default_steam_path():
|
|||||||
conf = get_config(xdg.config)
|
conf = get_config(xdg.config)
|
||||||
return conf["default_steam_path"]
|
return conf["default_steam_path"]
|
||||||
|
|
||||||
|
|
||||||
def test_pefile_length(default_steam_path):
|
def test_pefile_length(default_steam_path):
|
||||||
try:
|
try:
|
||||||
pe_file_path = PeFile.get_pefile_path(
|
pe_file_path = PeFile.get_pefile_path(Path(default_steam_path), APPID_DAYZ)
|
||||||
Path(default_steam_path), APPID_DAYZ
|
|
||||||
)
|
|
||||||
vers = PeFile.get_dayz_version(pe_file_path)
|
vers = PeFile.get_dayz_version(pe_file_path)
|
||||||
st = PeFile.dayz_version_to_str(vers).split(".")
|
st = PeFile.dayz_version_to_str(vers).split(".")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise e
|
raise e
|
||||||
assert len(st) == 3
|
assert len(st) == 3
|
||||||
|
|
||||||
|
|
||||||
def test_invalid_pefile_path():
|
def test_invalid_pefile_path():
|
||||||
with pytest.raises(VDFLoadError):
|
with pytest.raises(VDFLoadError):
|
||||||
try:
|
try:
|
||||||
@@ -42,11 +44,14 @@ def test_invalid_pefile_path():
|
|||||||
raise e
|
raise e
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize("fixture, exception", [
|
@pytest.mark.parametrize(
|
||||||
("not_in_library.vdf", AppNotInstalledError),
|
"fixture, exception",
|
||||||
("in_library_but_bad_path.vdf", AppMovedError),
|
[
|
||||||
("malformed.vdf", VDFLoadError),
|
("not_in_library.vdf", AppNotInstalledError),
|
||||||
])
|
("in_library_but_bad_path.vdf", AppMovedError),
|
||||||
|
("malformed.vdf", VDFLoadError),
|
||||||
|
],
|
||||||
|
)
|
||||||
def test_not_in_library(fixture, exception):
|
def test_not_in_library(fixture, exception):
|
||||||
fixture = fixture_path(fixture)
|
fixture = fixture_path(fixture)
|
||||||
with pytest.raises(exception):
|
with pytest.raises(exception):
|
||||||
@@ -55,6 +60,7 @@ def test_not_in_library(fixture, exception):
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise e
|
raise e
|
||||||
|
|
||||||
|
|
||||||
def test_on_second_drive(second_drive):
|
def test_on_second_drive(second_drive):
|
||||||
path = PeFile.get_app_path(second_drive, APPID_DAYZ)
|
path = PeFile.get_app_path(second_drive, APPID_DAYZ)
|
||||||
assert path == Path("/tmp")
|
assert path == Path("/tmp")
|
||||||
Reference in new issue
Block a user