Ejemplo n.º 1
0
 def test_functions_on_multiple_variables(self):
     template_text_generator = text_generator.TemplatedTextGenerator(
         templates_list=[
             "this is a {test.title} using multiple {variable.plural.title}"
         ])
     result = template_text_generator.generate({
         "test": "something",
         "variable": "instance"
     })
     self.assertEqual("this is a Something using multiple Instances",
                      result)
 def test_not_using_unusable_template(self):
     """ Tests if the generator is not raising an error when variables are missing to generate, and only uses other
     generator """
     possible_templates = ["This is {adjective}", "This is {noun}"]
     templated_text_generator = text_generator.TemplatedTextGenerator(
         templates_list=possible_templates)
     for _ in range(100):
         self.assertEqual(
             "This is possible",
             templated_text_generator.generate({"adjective": "possible"}))
     for _ in range(100):
         self.assertEqual(
             "This is a test",
             templated_text_generator.generate({"noun": "a test"}))
Ejemplo n.º 3
0
    def test_all_possible_outcomes(self):
        possible_templates = ["This is {adjective}", "This is {noun}"]
        templated_text_generator = text_generator.TemplatedTextGenerator(
            templates_list=possible_templates)
        expected = {"This is possible", "This is a test"}
        all_generations = set()
        for _ in range(10000):
            if all_generations == expected:
                break
            all_generations.add(
                templated_text_generator.generate({
                    "adjective": "possible",
                    "noun": "a test"
                }))

        self.assertEqual(expected, all_generations)
Ejemplo n.º 4
0
 def test_functions_on_variables(self):
     template_text_generator = text_generator.TemplatedTextGenerator(
         templates_list=["this is a {test.title}"])
     result = template_text_generator.generate({"test": "something"})
     self.assertEqual("this is a Something", result)
Ejemplo n.º 5
0
def createTemplatedTextGenerator(file):
    actual_file = os_util.to_actual_file(file, __file__)
    return text_generator.TemplatedTextGenerator(actual_file).generate
Ejemplo n.º 6
0
def create_templated_text_generator(filename):
    actual_file = os_util.to_actual_file(filename)
    return text_generator.TemplatedTextGenerator(actual_file).generate