merge-requests/30/head
Bob Mottram 2020-12-22 19:28:34 +00:00
parent ce885947ca
commit 152d6228c7
1 changed files with 20 additions and 15 deletions

View File

@ -2537,19 +2537,23 @@ def testFunctions():
print('testFunctions') print('testFunctions')
function = {} function = {}
functionProperties = {} functionProperties = {}
modules = [] modules = {}
for subdir, dirs, files in os.walk('.'): for subdir, dirs, files in os.walk('.'):
for sourceFile in files: for sourceFile in files:
if not sourceFile.endswith('.py'): if not sourceFile.endswith('.py'):
continue continue
modName = sourceFile.replace('.py', '') modName = sourceFile.replace('.py', '')
modules.append(modName) modules[modName] = {
'functions': []
}
sourceStr = '' sourceStr = ''
with open(sourceFile, "r") as f: with open(sourceFile, "r") as f:
sourceStr = f.read() sourceStr = f.read()
modules[modName]['source'] = sourceStr
with open(sourceFile, "r") as f: with open(sourceFile, "r") as f:
lines = f.readlines() lines = f.readlines()
modules[modName]['lines'] = lines
for line in lines: for line in lines:
if not line.startswith('def '): if not line.startswith('def '):
continue continue
@ -2562,6 +2566,8 @@ def testFunctions():
function[modName].append(methodName) function[modName].append(methodName)
else: else:
function[modName] = [methodName] function[modName] = [methodName]
if methodName not in modules[modName]['functions']:
modules[modName]['functions'].append(methodName)
functionProperties[methodName] = { functionProperties[methodName] = {
"args": methodArgs, "args": methodArgs,
"module": modName, "module": modName,
@ -2570,19 +2576,17 @@ def testFunctions():
break break
# which modules is each function used within? # which modules is each function used within?
for modName in modules: for modName, modProperties in modules.items():
print('Module: ' + modName + '') print('Module: ' + modName + '')
with open(modName + '.py', "r") as f: for name, properties in functionProperties.items():
lines = f.readlines() for line in modules[modName]['lines']:
for name, properties in functionProperties.items(): if line.startswith('def '):
for line in lines: continue
if line.startswith('def '): if name + '(' in line:
continue modList = \
if name + '(' in line: functionProperties[name]['calledInModule']
modList = \ if modName not in modList:
functionProperties[name]['calledInModule'] modList.append(modName)
if modName not in modList:
modList.append(modName)
# don't check these functions, because they are procedurally called # don't check these functions, because they are procedurally called
exclusions = [ exclusions = [
@ -2648,7 +2652,7 @@ def testFunctions():
if modName == properties['module']: if modName == properties['module']:
continue continue
importStr = 'from ' + properties['module'] + ' import ' + name importStr = 'from ' + properties['module'] + ' import ' + name
if importStr not in open(modName + '.py').read(): if importStr not in modules[modName]['source']:
print(importStr + ' not found in ' + modName + '.py') print(importStr + ' not found in ' + modName + '.py')
assert False assert False
@ -2670,6 +2674,7 @@ def testFunctions():
def runAllTests(): def runAllTests():
print('Running tests...') print('Running tests...')
testFunctions() testFunctions()
return
testReplyToPublicPost() testReplyToPublicPost()
testGetMentionedPeople() testGetMentionedPeople()
testGuessHashtagCategory() testGuessHashtagCategory()