From 76314d55b60a93a97ac3b790e2ad636d0817ada7 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Wed, 3 Mar 2021 19:15:32 +0000 Subject: [PATCH] Fix unit tests --- speaker.py | 54 ++++++++++++++++++++++++++++++------------------------ utils.py | 5 ++++- 2 files changed, 34 insertions(+), 25 deletions(-) diff --git a/speaker.py b/speaker.py index 062c0b72f..cf66c55a3 100644 --- a/speaker.py +++ b/speaker.py @@ -68,27 +68,29 @@ def _speakerPronounce(baseDir: str, sayText: str, translate: {}) -> str: Epicyon -> Epi-cyon """ pronounceFilename = baseDir + '/accounts/speaker_pronounce.txt' - convertDict = { - "Epicyon": "Epi-cyon", - "espeak": "e-speak", - "emoji": "emowji", - "clearnet": "clear-net", - "https": "H-T-T-P-S", - "HTTPS": "H-T-T-P-S", - "Tor": "Toor", - "🤔": ". " + translate["thinking emoji"], - "RT @": "Re-Tweet ", - "#": translate["hashtag"], - ":D": '. ' + translate["laughing"], - ":-D": '. ' + translate["laughing"], - ":)": '. ' + translate["smile"], - ";)": '. ' + translate["wink"], - ":(": '. ' + translate["sad face"], - ":-)": '. ' + translate["smile"], - ":-(": '. ' + translate["sad face"], - ";-)": '. ' + translate["wink"], - "*": "" - } + convertDict = {} + if translate: + convertDict = { + "Epicyon": "Epi-cyon", + "espeak": "e-speak", + "emoji": "emowji", + "clearnet": "clear-net", + "https": "H-T-T-P-S", + "HTTPS": "H-T-T-P-S", + "Tor": "Toor", + "🤔": ". " + translate["thinking emoji"], + "RT @": "Re-Tweet ", + "#": translate["hashtag"], + ":D": '. ' + translate["laughing"], + ":-D": '. ' + translate["laughing"], + ":)": '. ' + translate["smile"], + ";)": '. ' + translate["wink"], + ":(": '. ' + translate["sad face"], + ":-)": '. ' + translate["smile"], + ":-(": '. ' + translate["sad face"], + ";-)": '. ' + translate["wink"], + "*": "" + } if os.path.isfile(pronounceFilename): with open(pronounceFilename, 'r') as fp: pronounceList = fp.readlines() @@ -124,7 +126,10 @@ def speakerReplaceLinks(sayText: str, translate: {}, text = text.replace(ch, ' ') replacements = {} wordsList = text.split(' ') - linkedStr = translate['Linked'] + if translate.get('Linked'): + linkedStr = translate['Linked'] + else: + linkedStr = 'Linked' prevWord = '' for word in wordsList: if word.startswith(':'): @@ -133,8 +138,9 @@ def speakerReplaceLinks(sayText: str, translate: {}, continue # replace mentions, but not re-tweets if word.startswith('@') and not prevWord.endswith('RT'): - replacements[word] = \ - translate['mentioning'] + ' ' + word[1:] + ',' + if translate.get('mentioning'): + replacements[word] = \ + translate['mentioning'] + ' ' + word[1:] + ',' prevWord = word domain = None diff --git a/utils.py b/utils.py index 326f52c18..7460417dc 100644 --- a/utils.py +++ b/utils.py @@ -678,7 +678,10 @@ def getGenderFromBio(baseDir: str, actor: str, personCache: {}, if not personCache.get(actor): return None bioFound = None - pronounStr = translate['pronoun'].lower() + if translate: + pronounStr = translate['pronoun'].lower() + else: + pronounStr = 'pronoun' if personCache[actor].get('actor'): # is gender defined as a profile tag? if personCache[actor]['actor'].get('attachment'):