• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In
Build has been canceled!

SPF-OST / pytrnsys_gui / 11662562960

29 Oct 2024 03:09PM UTC coverage: 67.508% (-0.08%) from 67.591%
11662562960

push

github

web-flow
Merge pull request #564 from SPF-OST/560-black-change-line-length-to-pep8-standard-of-79-and-check-ci-reaction

changed line length in black to 79

1054 of 1475 new or added lines in 174 files covered. (71.46%)

150 existing lines in 74 files now uncovered.

10399 of 15404 relevant lines covered (67.51%)

0.68 hits per line

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

28.13
/trnsysGUI/loadDdckFile.py
1
import dataclasses as _dc
1✔
2
import pathlib as _pl
1✔
3
import shutil as _su
1✔
4

5
import PyQt5.QtWidgets as _qtw
1✔
6

7
import pytrnsys.utils.result as _res
1✔
8
import trnsysGUI.common.cancelled as _cancel
1✔
9
import trnsysGUI.internalPiping as _ip
1✔
10
import trnsysGUI.proforma.convertXmlTmfToDdck as _pro
1✔
11
import trnsysGUI.proforma.createModelConnections as _pcmc
1✔
12
import trnsysGUI.proforma.dialogs.convertDialog as _pcd
1✔
13
import trnsysGUI.warningsAndErrors as _warn
1✔
14

15

16
@_dc.dataclass
1✔
17
class DdckFileLoader:
1✔
18
    hasInternalPipingsProvider: _ip.HasInternalPipingsProvider
1✔
19

20
    def loadDdckFile(self, targetDirPath: _pl.Path) -> None:
1✔
NEW
21
        sourceFilePathString, _ = _qtw.QFileDialog.getOpenFileName(
×
22
            None, "Load file"
23
        )
24
        if not sourceFilePathString:
×
25
            return
×
26

27
        sourceFilePath = _pl.Path(sourceFilePathString)
×
28

29
        isSourceProformaFile = self._isProformaFilePath(sourceFilePath)
×
NEW
30
        targetSuffix = (
×
31
            ".ddck" if isSourceProformaFile else sourceFilePath.suffix
32
        )
33

34
        targetFilePathStem = targetDirPath / sourceFilePath.stem
×
35
        targetFilePath = targetFilePathStem.with_suffix(targetSuffix)
×
36

37
        if targetFilePath.is_dir():
×
38
            message = f"""\
×
39
        A directory of the name `{targetFilePath.name}` already exists. Please change the name of the file before
40
        importing or remove the directory."""
41
            _warn.showMessageBox(message, _warn.Title.WARNING)
×
42
            return
×
43

44
        if targetFilePath.is_file():
×
45
            message = f"""\
×
46
                    A file of the name `{targetFilePath.name}` already exists. Do you want to overwrite it?"""
47

NEW
48
            standardButton = _qtw.QMessageBox.question(
×
49
                None, "Overwrite file?", message
50
            )
NEW
51
            if (
×
52
                standardButton
53
                != _qtw.QMessageBox.StandardButton.Yes  # pylint: disable=no-member
54
            ):
UNCOV
55
                return
×
56

57
        targetContainingDirPath = targetFilePath.parent
×
58
        if not targetContainingDirPath.exists():
×
59
            message = f"The target parent directory `{targetContainingDirPath}` doesn't exist. Should it be created?"
×
60
            standardButton = _qtw.QMessageBox.question(
×
61
                None,
62
                message,
63
                "Create directory?",
64
                _qtw.QMessageBox.Ok | _qtw.QMessageBox.Cancel,
65
            )
66

67
            if standardButton != _qtw.QMessageBox.Ok:
×
68
                return
×
69

70
        targetContainingDirPath.mkdir(parents=True, exist_ok=True)
×
71

72
        if not isSourceProformaFile:
×
73
            _su.copy(sourceFilePath, targetFilePath)
×
74
            return
×
75

NEW
76
        self._convertAndLoadProformaFileIntoFolder(
×
77
            sourceFilePath, targetFilePath
78
        )
79

80
    def _convertAndLoadProformaFileIntoFolder(
1✔
81
        self, sourceFilePath: _pl.Path, targetFilePath: _pl.Path
82
    ) -> None:
UNCOV
83
        hasInternalPipingsWithDdckPlaceholders = [
×
84
            hip
85
            for hip in self.hasInternalPipingsProvider.getInternalPipings()
86
            if hip.hasDdckPlaceHolders()
87
        ]
88

89
        dialogMaybeCancelled = _pcd.ConvertDialog.showDialogAndGetResults(
×
90
            hasInternalPipingsWithDdckPlaceholders, targetFilePath
91
        )
92
        if _cancel.isCancelled(dialogMaybeCancelled):
×
93
            return
×
94
        dialogResult = _cancel.value(dialogMaybeCancelled)
×
95

NEW
96
        createConnectionsResult = (
×
97
            _pcmc.createModelConnectionsFromInternalPiping(
98
                dialogResult.internalPiping
99
            )
100
        )
101
        if _res.isError(createConnectionsResult):
×
102
            _warn.showMessageBox(_res.error(createConnectionsResult).message)
×
103
            return
×
104
        suggestedHydraulicConnections = _res.value(createConnectionsResult)
×
105

106
        maybeCancelled = _pro.convertXmltmfToDdck(
×
107
            sourceFilePath,
108
            suggestedHydraulicConnections,
109
            dialogResult.outputFilePath,
110
        )
111
        if _cancel.isCancelled(maybeCancelled):
×
112
            return
×
113
        result = _cancel.value(maybeCancelled)
×
114
        if _res.isError(result):
×
115
            _warn.showMessageBox(_res.error(result).message)
×
116
            return
×
117

118
    @staticmethod
1✔
119
    def _isProformaFilePath(filePath: _pl.Path) -> bool:
1✔
120
        return filePath.suffix == ".xmltmf"
×
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