Skip to content
This repository has been archived by the owner on May 8, 2024. It is now read-only.

Commit

Permalink
style: cleaning up formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
BobBorges committed Feb 22, 2024
1 parent fa4e149 commit fac4e4b
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions test/empty-speech.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
import warnings




class EmptyElement(Warning):

def __init__(self, m):
Expand All @@ -24,21 +26,18 @@ def __str__(self):
return self.message


class Test(unittest.TestCase):

def protocol_iter(self):
"""
Get protocols.
"""
return sorted(list(protocol_iterators("corpus/protocols/", start=1867, end=2022)))

class Test(unittest.TestCase):

def test_no_empty_speech(self):
"""
Test protocol has no empty `u` or `seg` elements
"""
rows = []
protocols = self.protocol_iter()
protocols = sorted(list(protocol_iterators("corpus/protocols/",
start=1867,
end=2022)))
for p in tqdm(protocols, total=len(protocols)):
root, ns = parse_protocol(p, get_ns=True)
for elem in root.iter(f'{ns["tei_ns"]}u'):
Expand All @@ -47,17 +46,13 @@ def test_no_empty_speech(self):
u_id = elem.attrib[f'{ns["xml_ns"]}id']
rows.append([p, "u", u_id])
warnings.warn(f"Empty u-elem: {p}, {u_id}", EmptyElement)
else:
print("oh no, U")
else:
for seg in elem:
if not seg.text or seg.text.strip() == '':
if f'{ns["xml_ns"]}id' in seg.attrib:
seg_id = seg.attrib[f'{ns["xml_ns"]}id']
rows.append([p, "seg", seg_id])
warnings.warn(f"Empty seg-elem: {p}, {seg_id}", EmptyElement)
else:
print("oh no, SEG")
if len(rows) > 0:
config = fetch_config("empty-speech")
if config and config["write_empty_speeches"]:
Expand All @@ -71,5 +66,8 @@ def test_no_empty_speech(self):

self.assertEqual(len(rows), 0)




if __name__ == '__main__':
unittest.main()

0 comments on commit fac4e4b

Please sign in to comment.