From d1b1d17f94287ddbb2f5337057efa2c32f07ffc3 Mon Sep 17 00:00:00 2001 From: Maximilien Rigaut Date: Wed, 3 May 2017 20:30:14 +0200 Subject: [PATCH] Implemented tests of file_parser --- sites/example_website/_config.txt | 9 +++++-- test.py | 40 ++++++++++++++++++++++++------- 2 files changed, 39 insertions(+), 10 deletions(-) diff --git a/sites/example_website/_config.txt b/sites/example_website/_config.txt index 6fb3e11..0fc613f 100644 --- a/sites/example_website/_config.txt +++ b/sites/example_website/_config.txt @@ -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__ diff --git a/test.py b/test.py index ce26e41..97cbd4f 100644 --- a/test.py +++ b/test.py @@ -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)