Commit a4180d32 authored by Markus Scheidgen's avatar Markus Scheidgen
Browse files

Merge branch 'parser-tests' into 'v0.10.1'

Parser tests

See merge request !289
parents a574e1c1 bb56899d
Pipeline #96653 passed with stages
in 22 minutes and 58 seconds
Subproject commit b6b9715460a414af4af433bc44a832c97319080f
Subproject commit 9cddb2a7ab2d3fd56510a6ef853003f8fe9a516f
Subproject commit 44d5861d0503976714ce1a1e09bac2aa3495ddf9
Subproject commit f3460ebca058f039126339e064697ee85727a34d
Subproject commit 139ab4a5e288542f4343db3419597fdeddbde3f4
Subproject commit 3eea49a540d8a174cde5d396bce55291c19bb496
Subproject commit 8fc5f723a72e5fe3722a43a68ca9246a7633a760
Subproject commit 78d4cbc11f65c00358ad3af71ed2163bdb07955f
Subproject commit b3850be63dab9ce9a823eb2a32ff7ced541265be
Subproject commit 92f246af2351812af8b300f1473bf24bff5addc5
Subproject commit 2fec8017097f8483c75496b6fc4d4917a9581c1c
Subproject commit c1232f7cc5a72500341e48b4e6c37a480b534e5d
Subproject commit f425f19f2f83eb68481a0bf7248cbcfe6592443d
Subproject commit 714496b48c6710e02d288d2816ec08781c43c66f
Subproject commit ae88b8cccddbb4da886edf9c926f7f0c792b3002
Subproject commit 33eacd5ad0535cbf9cc39755177eb988975db0b8
Subproject commit 6ebe206cb99f5bdf008f81f7bc8e4e434414460d
Subproject commit 9258f9521823698fcdfbdf85d5665d7694fafe5e
......@@ -256,7 +256,7 @@ class DataTextParser(FileParser):
else:
if self._mainfile_contents is None:
self._mainfile_contents = self.mainfile_obj.read()
self._file_handler = np.fromstring(self._mainfile_contents, dtype=self._dtype)
self._file_handler = np.frombuffer(self._mainfile_contents, dtype=self._dtype)
except Exception:
return
......@@ -290,6 +290,20 @@ class TextParser(FileParser):
self._file_pad: int = 0
if quantities is None:
self.init_quantities()
# check quantity patterns are valid
re_has_group = re.compile(r'\(.+\)')
for i in range(len(self.quantities) - 1, -1, -1):
valid = True
try:
if re_has_group.search(self.quantities[i].re_pattern.pattern.decode()) is None:
valid = False
except Exception:
valid = False
if not valid:
self.logger.error(
'Invalid quantity pattern', data=dict(quantity=self.quantities[i].name))
self.quantities.pop(i)
self._re_findall = None
def copy(self):
'''
......@@ -367,11 +381,17 @@ class TextParser(FileParser):
yield key, self.get(key)
def _parse_quantities(self, quantities):
re_findall = '|'.join([q.re_pattern.pattern.decode() for q in quantities])
if len(quantities) == 1:
# necessary to add a dummy variable to make multiple matches
re_findall = '%s|(__dummy__)' % re_findall
re_findall = re_findall.encode()
if len(self._results) == 0 and self._re_findall is not None:
# maybe an opt
re_findall = self._re_findall
else:
re_findall = '|'.join([q.re_pattern.pattern.decode() for q in quantities])
if len(quantities) == 1:
# necessary to add a dummy variable to make multiple matches
re_findall = '%s|(__dummy__)' % re_findall
re_findall = re_findall.encode()
if self._re_findall is None:
self._re_findall = re.compile(re_findall)
# map matches to quantities
matches = re.findall(re_findall, self.file_mmap)
......
......@@ -112,7 +112,7 @@ class XMLParser(FileParser):
v = element.attrib.get(child, None)
if v is None:
v = element.findall(child)
v = [e.text for e in v]
v = [e.text if e.text is not None else '' for e in v]
if v:
val.append(v)
......@@ -127,7 +127,6 @@ class XMLParser(FileParser):
val = dict()
for k, v in val_in.items():
val[k] = convert_value(v)
val = val_in
elif isinstance(val_in, str):
# exponential formatting
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment