Implemented tests of file_parser

This commit is contained in:
Maximilien Rigaut 2017-05-03 20:30:14 +02:00
parent beae69f696
commit d1b1d17f94
2 changed files with 39 additions and 10 deletions

View File

@ -21,9 +21,14 @@ Be wary that _ is a reserved character
Technically those lines are not comments but since the text content of config files is ignored, it acts like one
__en__
This part in a En only comment
__/en__
__fr__
Cette partie est un commentaire français seulement
__/fr__
__comment__
You can also comment anywhere by using any __lang__ not in the scope of generated ones
You can also comment anywhere by using any
__lang__ not in the scope of generated ones
__/comment__

40
test.py
View File

@ -12,7 +12,7 @@ term=Terminal()
unit=minitest.testUnit
group=minitest.testGroup
testVky=group(name="vkyWeb_all",terminal=term,verbose=1,align=40)
testVky=group(name="vkyWeb_all",terminal=term,verbose=1,align=42)
#testConfig=group()
#testParser=group(name="parser",terminal=term,prefix="| ")
#testTree=group(name="tree",terminal=term,prefix="| ")
@ -40,7 +40,7 @@ class testParser(unit):
def test(self):
try:
config_langs=["*","en","fr"]
#raise IOError("Impossible to load config")
self.currentTest="parser:load"
config=file_parser.parse_file("sites/example_website/_config.txt")
@ -58,9 +58,8 @@ class testParser(unit):
else:
self.addFailure("config is not a dict")
self.currentTest="parser_config:lang"
for lang in ["*","en","fr"]:
for lang in config_langs:
if lang not in config.list_of_lang:
self.addFailure("lang {} not in config".format(lang))
self.addSucess()
@ -74,15 +73,40 @@ class testParser(unit):
else:
self.addFailure("content is supposed to be a list of lines&langs")
self.currentTest="parser_config:generator"
gen=config.get_next_line("*")
if type(gen)==types.GeneratorType:
pass
self.addSucess()
self.addSucess()
else:
self.addFailure("get_next_line is supposed to be a generator")
self.currentTest="parser_config:generator:lang"
content_by_lang={'*':[],'fr':[],'en':[]}
for line in config.content:
txt,langs=line[0],line[1]
for lang in langs:
if lang in ["fr","en"]:
content_by_lang[lang].append(txt)
elif lang=="*":
for l in config_langs:
content_by_lang[l].append(txt)
succes=True
for l in ["en","fr"]:
generator_table=[e for e in config.get_next_line(l)]
if len(content_by_lang[l])!=len(generator_table):
self.addFailure("generator and model don't have the same length [{}]".format(l))
succes=False
for i in xrange(len(generator_table)):
if generator_table[i]!=content_by_lang[l][i]:
self.addFailure("generator and model have different content [{}:{}]".format(l,i))
succes=False
if succes:
self.addSucess()
self.currentTest="parser_config:generator:type"
for l in config.get_next_line("*"):
print l
if type(l)!=str:
self.addFailure("type is supposed to be a string")
#print index.content
except Exception as e:
self.addFailure(e)