feat: dzgui 7 alpha

This commit is contained in:
aclist committed 2025-12-08 17:32:25 +09:00
1 parent 1acdbd58c5
commit 2e5b771137
150 files changed
+10359

No files matched your search

View File
Whitespace-only changes.
+5
View File
@@ -0,0 +1,5 @@
from pathlib import Path
CWD = Path(__file__).parent
def fixture_path(fixture: str) -> str:
return str(CWD / fixture)
+16
View File
@@ -0,0 +1,16 @@
{
"bm_api": "000",
"fav_server": "127.0.0.0:80:80",
"fav_label": "My server",
"name": "John Doe",
"debug": false,
"branch": "testing",
"fullscreen": false,
"steam_api": "000",
"auto_install": true,
"default_steam_path": "/tmp",
"preferred_client": "steam",
"ip_list": [
"127.0.0.0:80:80"
]
}
+45
View File
@@ -0,0 +1,45 @@
#Path to DayZ installation
steam_path="/tmp"
#Battlemetrics API key
api_key=""
#Favorited server IP:PORT array
ip_list=(
)
#Favorite server to fast-connect to (limit one)
fav_server=""
#Favorite server label (human readable)
fav_label=""
#Custom player name (optional, required by some servers)
name=""
#Set to 1 to perform dry-run and print launch options
debug="1"
#Toggle stable/testing branch
branch="testing"
#Start in fullscreen
fullscreen="false"
#Steam API key
steam_api=""
#Auto-install mods
auto_install="2"
#Automod staging directory
staging_dir="/tmp"
#Path to default Steam client
default_steam_path="/tmp"
#Preferred Steam launch command (for Flatpak support)
preferred_client="steam"
#DZGUI source path
src_path=""
+45
View File
@@ -0,0 +1,45 @@
#Path to DayZ installation
steam_path="/tmp"
#Battlemetrics API key
api_key=""
#Favorited server IP:PORT array
ip_list=(
)
#Favorite server to fast-connect to (limit one)
fav_server=""
#Favorite server label (human readable)
fav_label=""
#Custom player name (optional, required by some servers)
name=""
#Set to 1 to perform dry-run and print launch options
debug=""
#Toggle stable/testing branch
branch="testing"
#Start in fullscreen
fullscreen="false"
#Steam API key
steam_api=""
#Auto-install mods
auto_install="0"
#Automod staging directory
staging_dir="/tmp"
#Path to default Steam client
default_steam_path="/tmp"
#Preferred Steam launch command (for Flatpak support)
preferred_client="steam"
#DZGUI source path
src_path=""
+11
View File
@@ -0,0 +1,11 @@
"libraryfolders"
{
"0"
{
"path" "/not/a/path"
"apps"
{
"221100" "0"
}
}
}
+19
View File
@@ -0,0 +1,19 @@
"libraryfolders"
{
"0"
{
"path" "/not/a/path"
"apps"
{
"0" "0"
}
}
"1"
{
"path" "/tmp"
"apps"
{
"221100" "0"
}
}
}
+1
View File
@@ -0,0 +1 @@
"not a vdf"
+11
View File
@@ -0,0 +1,11 @@
"libraryfolders"
{
"0"
{
"path" "/not/a/path"
"apps"
{
"0" "0"
}
}
}
+8
View File
@@ -0,0 +1,8 @@
def test_headings():
with open("CHANGELOG.md", "r") as f:
lines = f.readlines()
for line in lines:
if line.startswith("#"):
pass
# TODO: use regex
pass
+79
View File
@@ -0,0 +1,79 @@
import json
import pytest
from dzgui.config.query import get_config
from dzgui.config.xdg import get_xdg_paths, parse_filepaths
from dzgui.config import convert
from tests.fixtures import fixture_path
pytestmark = pytest.mark.config
@pytest.fixture
def legacy_config():
return fixture_path("dztuirc_one")
@pytest.fixture
def keys():
return [
"bm_api",
"fav_server",
"fav_label",
"name",
"debug",
"branch",
"fullscreen",
"steam_api",
"auto_install",
"default_steam_path",
"client",
"ip_list",
"use_miles"
]
@pytest.fixture
def config():
paths = get_xdg_paths()
xdg = parse_filepaths(paths)
return get_config(xdg.config)
@pytest.mark.post_install
def test_invalid_config_value(config):
with pytest.raises(Exception):
assert config["foo"] is None
@pytest.mark.post_install
def test_default_config_values(keys, config):
for key in keys:
assert config[key] is not None
@pytest.mark.post_install
def test_contains_invalid_values(keys, config):
for key in config:
assert key in keys
@pytest.mark.parametrize("fixture, expect", [
("dztuirc_one", (False, True, True)),
("dztuirc_two", (False, False, False)),
])
def test_bool_conversion(fixture, expect):
fixture = fixture_path(fixture)
j = convert.rc2json(fixture)
j = json.loads(j)
assert j["fullscreen"] == expect[0]
assert j["debug"] == expect[1]
assert j["auto_install"] == expect[2]
assert not j["use_miles"]
def test_key_conversion(legacy_config):
j = convert.rc2json(legacy_config)
j = json.loads(j)
keys = ["api_key", "staging_dir", "src_path", "steam_path", "preferred_client"]
for key in keys:
assert key not in j
# TODO: test that when a config file is created from scratch, it contains all values
+19
View File
@@ -0,0 +1,19 @@
import pytest
import time
from dzgui.util import cooldown
def test_time_under():
time_before = cooldown.get_time()
time.sleep(1)
result = cooldown.is_elapsed(time_before)
assert result is False
@pytest.mark.slow
def test_time_over():
time_before = cooldown.get_time()
time.sleep(31)
result = cooldown.is_elapsed(time_before)
assert result is True
+32
View File
@@ -0,0 +1,32 @@
import pytest
from dzgui.api.servers import validate_ip
def test_ip_validation() -> None:
ip = "192.168.1.1:100"
record = validate_ip(ip)
assert record.ip == "192.168.1.1"
assert record.gameport == 0
assert record.qport == 100
def test_invalid_port() -> None:
ip = "192.168.1.1:foo"
with pytest.raises(Exception):
validate_ip(ip)
@pytest.mark.parametrize("port", [-1, 65536])
def test_port_out_of_range(port: int) -> None:
ip = f"192.168.1.1:{port}"
with pytest.raises(Exception):
validate_ip(ip)
def test_invalid_socket() -> None:
ip = "0.0.0.0"
with pytest.raises(Exception):
validate_ip(ip)
# TODO: ?
def test_ipdb() -> None:
pass
+28
View File
@@ -0,0 +1,28 @@
from dzgui.util import localize
def test_de(monkeypatch):
monkeypatch.setenv("LC_CTYPE", "de_DE.UTF-8")
localize.set_locale()
assert localize.number(9900) == "9.900"
assert localize.number(99.88) == "99,88"
def test_en(monkeypatch):
monkeypatch.setenv("LC_CTYPE", "en_US.UTF-8")
localize.set_locale()
assert localize.number(9900) == "9,900"
assert localize.number(99.88) == "99.88"
def test_none(monkeypatch):
localize.set_locale()
assert localize.number(9900) == "9,900"
assert localize.number(99.88) == "99.88"
def test_empty(monkeypatch):
monkeypatch.setenv("LC_CTYPE", "")
localize.set_locale()
assert localize.number(9900) == "9,900"
assert localize.number(99.88) == "99.88"
+60
View File
@@ -0,0 +1,60 @@
import pytest
from pathlib import Path
import dzgui.api.pefile as PeFile
from dzgui.api.pefile import (VDFLoadError, AppNotInstalledError, AppMovedError)
from dzgui.config.query import get_config
from dzgui.config.xdg import get_xdg_paths, parse_filepaths
from dzgui.const.constants import APPID_DAYZ
from tests.fixtures import fixture_path
pytestmark = pytest.mark.pefile
@pytest.fixture
def second_drive():
return fixture_path("in_library_on_second_drive.vdf")
@pytest.fixture
def default_steam_path():
paths = get_xdg_paths()
xdg = parse_filepaths(paths)
conf = get_config(xdg.config)
return conf["default_steam_path"]
def test_pefile_length(default_steam_path):
try:
pe_file_path = PeFile.get_pefile_path(
Path(default_steam_path), APPID_DAYZ
)
vers = PeFile.get_dayz_version(pe_file_path)
st = PeFile.dayz_version_to_str(vers).split(".")
except Exception as e:
raise e
assert len(st) == 3
def test_invalid_pefile_path():
with pytest.raises(VDFLoadError):
try:
PeFile.get_pefile_path(Path("/not/a/path"), APPID_DAYZ)
except Exception as e:
raise e
@pytest.mark.parametrize("fixture, exception", [
("not_in_library.vdf", AppNotInstalledError),
("in_library_but_bad_path.vdf", AppMovedError),
("malformed.vdf", VDFLoadError),
])
def test_not_in_library(fixture, exception):
fixture = fixture_path(fixture)
with pytest.raises(exception):
try:
PeFile.get_app_path(fixture, APPID_DAYZ)
except Exception as e:
raise e
def test_on_second_drive(second_drive):
path = PeFile.get_app_path(second_drive, APPID_DAYZ)
assert path == Path("/tmp")
+26
View File
@@ -0,0 +1,26 @@
import pytest
from dzgui.config.query import get_config
from dzgui.config.xdg import get_xdg_paths, parse_filepaths
from dzgui.api import probe
pytestmark = pytest.mark.webtest
@pytest.fixture
def config():
paths = get_xdg_paths()
xdg = parse_filepaths(paths)
return get_config(xdg.config)
def test_ipdb():
assert probe.test_ipdb()
def test_steam(config):
key = config["steam_api"]
assert probe.test_steam_api(key)
def test_bm(config):
key = config["bm_api"]
assert probe.test_bm_api(key)