Skip to content

Commit 17862fa

Browse files
committed
Remove match from error getter
1 parent 8c15d04 commit 17862fa

File tree

3 files changed

+28
-25
lines changed

3 files changed

+28
-25
lines changed

exceptions.py

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -18,28 +18,24 @@ class srcMLInvalidConstruction(Exception):
1818
def __init__(self, msg):
1919
super().__init__(msg)
2020

21+
22+
SRCML_STATUS_ERROR_STRINGS = {
23+
srcMLStatus.ERROR: "srcMLStatus.ERROR: General srcML Error occured",
24+
srcMLStatus.INVALID_ARGUMENT: "srcMLStatus.INVALID_ARGUMENT: An invalid argument was passed",
25+
srcMLStatus.INVALID_INPUT: "srcMLStatus.INVALID_INPUT: The provided input was invalid",
26+
srcMLStatus.INVALID_IO_OPERATION: "srcMLStatus.INVALID_IO_OPERATION: Unable to execute read I/O operation (input might be read-only)",
27+
srcMLStatus.IO_ERROR: "srcMLStatus.IO_ERROR: Unable to open provided file",
28+
srcMLStatus.UNINITIALIZED_UNIT: "srcMLStatus.UNINITIALIZED_UNIT: Unit is uninitialized",
29+
srcMLStatus.UNSET_LANGUAGE: "srcMLStatus.UNSET_LANGUAGE: There is no language set",
30+
srcMLStatus.NO_TRANSFORMATION: "srcMLStatus.NO_TRANSFORMATION: There are no transformations",
31+
}
2132
class srcMLException(Exception):
2233
def __init__(self,error_code):
2334
self.error_code = error_code
24-
match error_code:
25-
case srcMLStatus.ERROR:
26-
error_string = "srcMLStatus.ERROR: General srcML Error occured"
27-
case srcMLStatus.INVALID_ARGUMENT:
28-
error_string = "srcMLStatus.INVALID_ARGUMENT: An invalid argument was passed"
29-
case srcMLStatus.INVALID_INPUT:
30-
error_string = "srcMLStatus.INVALID_INPUT: The provided input was invalid"
31-
case srcMLStatus.INVALID_IO_OPERATION:
32-
error_string = "srcMLStatus.INVALID_IO_OPERATION: Unable to execute read I/O operation (input might be read-only)"
33-
case srcMLStatus.IO_ERROR:
34-
error_string = "srcMLStatus.IO_ERROR: Unable to open provided file"
35-
case srcMLStatus.UNINITIALIZED_UNIT:
36-
error_string = "srcMLStatus.UNINITIALIZED_UNIT: Unit is uninitialized"
37-
case srcMLStatus.UNSET_LANGUAGE:
38-
error_string = "srcMLStatus.UNSET_LANGUAGE: There is no language set"
39-
case srcMLStatus.NO_TRANSFORMATION:
40-
error_string = "srcMLStatus.NO_TRANSFORMATION: There are no transformations"
41-
case _:
42-
error_string =f"Unknown srcMLStatus: error code {self.error_code}"
35+
if error_code not in SRCML_STATUS_ERROR_STRINGS:
36+
error_string = f"Unknown srcMLStatus: error code {self.error_code}"
37+
else:
38+
error_string = SRCML_STATUS_ERROR_STRINGS[error_code]
4339
super().__init__(error_string)
4440

4541
class srcMLInvalidResultType(Exception):

testsuite/test_srcml_unit_get.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,4 +120,17 @@
120120
#################################################
121121

122122

123+
#################################################
124+
# srcml_unit_get_loc
125+
################################################# 1
126+
locs = [142,35,820,115,399,119,70,51,16,38,97,43,93,32,104,31,17,68,46,170,98,95,41,254,34,92,52]
127+
archive = pylibsrcml.srcMLArchiveRead("data_big.xml")
128+
i = 0
129+
for unit in archive:
130+
print(unit.get_loc())
131+
assert unit.get_loc() == locs[i]
132+
i += 1
133+
#################################################
134+
135+
123136
archive.close()

values.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,6 @@ class srcMLOption:
4040
# ARCHIVE = 1<<14
4141
# HASH = 1<<15
4242

43-
class srcMLArchiveType:
44-
INAVLID = 0
45-
RW = 1
46-
READ = 2
47-
WRITE = 3
48-
4943
class SourceOutputEOL:
5044
AUTO = 0 # Source-code end of line determined automatically
5145
NATIVE = 0 # Source-code end of line determined according to operating system

0 commit comments

Comments
 (0)