• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

SPF-OST / pytrnsys_gui / 16883947425

11 Aug 2025 03:03PM UTC coverage: 67.786% (-0.07%) from 67.858%
16883947425

push

github

web-flow
Merge pull request #602 from SPF-OST/crash-without-settings

Don't crash if no settings available.

16 of 45 new or added lines in 5 files covered. (35.56%)

9 existing lines in 4 files now uncovered.

10460 of 15431 relevant lines covered (67.79%)

0.68 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

75.36
/trnsysGUI/settings.py
1
import dataclasses as _dc
1✔
2
import pathlib as _pl
1✔
3
import typing as _tp
1✔
4
import uuid as _uuid
1✔
5

6
import appdirs as _ad
1✔
7

8
import pytrnsys.utils.serialization as _ser
1✔
9

10

11
@_dc.dataclass
1✔
12
class SettingsVersion0(_ser.UpgradableJsonSchemaMixinVersion0):
1✔
13
    @classmethod
1✔
14
    def getVersion(cls) -> _uuid.UUID:
1✔
15
        return _uuid.UUID("f7a2c37c-ce82-4a4a-9869-80f00083275b")
1✔
16

17
    trnsysBinaryDirPath: str
1✔
18

19

20
@_dc.dataclass
1✔
21
class SettingsVersion1(_ser.UpgradableJsonSchemaMixin):
1✔
22
    @classmethod
1✔
23
    def getVersion(cls) -> _uuid.UUID:
1✔
24
        return _uuid.UUID("e5ea1fbd-1be9-4415-b3e9-7f3a2a11d216")
1✔
25

26
    trnsysBinaryPath: str
1✔
27

28
    @classmethod
1✔
29
    def getSupersededClass(cls) -> _tp.Type[SettingsVersion0]:
1✔
30
        return SettingsVersion0
1✔
31

32
    @classmethod
1✔
33
    def upgrade(
1✔
34
        cls, superseded: _ser.UpgradableJsonSchemaMixinVersion0
35
    ) -> "SettingsVersion1":
NEW
36
        assert isinstance(superseded, SettingsVersion0)
×
37

UNCOV
38
        trnsysBinaryPath = (
×
39
            _pl.Path(superseded.trnsysBinaryDirPath) / "TRNExe.exe"
40
        )
NEW
41
        return SettingsVersion1(str(trnsysBinaryPath))
×
42

43

44
@_dc.dataclass
1✔
45
class Settings(_ser.UpgradableJsonSchemaMixin):
1✔
46
    @staticmethod
1✔
47
    def create(
1✔
48
        trnsysBinaryDirPath: _pl.Path, recentProjects: list[_pl.Path]
49
    ) -> "Settings":
50
        return Settings(str(trnsysBinaryDirPath), list(recentProjects))
×
51

52
    _SETTINGS_FILE_NAME = "settings.json"
1✔
53

54
    trnsysBinaryPath: str
1✔
55

56
    recentProjects: list
1✔
57

58
    @classmethod
1✔
59
    def tryLoadOrNone(cls) -> _tp.Optional["Settings"]:
1✔
60
        settingsFilePath = cls._getSettingsFilePath()
1✔
61

62
        if not settingsFilePath.exists():
1✔
63
            return None
×
64

65
        data = settingsFilePath.read_text()
1✔
66

67
        return Settings.from_json(data)
1✔
68

69
    @classmethod
1✔
70
    def load(cls) -> "Settings":
1✔
71
        settings = cls.tryLoadOrNone()
1✔
72

73
        if not settings:
1✔
74
            raise RuntimeError("No settings found.")
×
75

76
        return settings
1✔
77

78
    def save(self) -> None:
1✔
79
        settingsFilePath = self._getSettingsFilePath()
×
80

81
        settingsDirPath = settingsFilePath.parent
×
82
        if not settingsDirPath.exists():
×
83
            settingsDirPath.mkdir(parents=True)
×
84

85
        data = self.to_json(indent=4)
×
86
        settingsFilePath.write_text(data)
×
87

88
    @classmethod
1✔
89
    def _getSettingsFilePath(cls) -> _pl.Path:
1✔
90
        userConfigDirPath = _pl.Path(
×
91
            _ad.user_config_dir("pytrnsys-gui", "SPF OST")
92
        )
93
        settingsFilePath = userConfigDirPath / cls._SETTINGS_FILE_NAME
×
94
        return settingsFilePath
×
95

96
    @classmethod
1✔
97
    def getSupersededClass(cls) -> _tp.Type[SettingsVersion1]:
1✔
98
        return SettingsVersion1
1✔
99

100
    @classmethod
1✔
101
    def upgrade(
1✔
102
        cls, superseded: _ser.UpgradableJsonSchemaMixinVersion0
103
    ) -> "Settings":
NEW
104
        assert isinstance(superseded, SettingsVersion1)
×
105

UNCOV
106
        return Settings.create(_pl.Path(superseded.trnsysBinaryPath), [])
×
107

108
    @classmethod
1✔
109
    def getVersion(cls) -> _uuid.UUID:
1✔
110
        return _uuid.UUID("c49c052a-f41a-481f-9849-2f6e7185e3cd")
1✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc