Ejemplo n.º 1
0
def profile():
    #------------------------------------------------------------------------------
    # Setup a profile
    #------------------------------------------------------------------------------
    pr = cProfile.Profile()
    #------------------------------------------------------------------------------
    # Enter setup code below
    #------------------------------------------------------------------------------
    # Optional: include setup code below
    from Naked.toolshed.ink import Template, Renderer
    #------------------------------------------------------------------------------
    # Start profiler
    #------------------------------------------------------------------------------
    pr.enable()

    #------------------------------------------------------------------------------
    # Enter code to be profiled below
    #------------------------------------------------------------------------------
        # include profiled code here
    for x in range(50000):
        template = Template("This is a of the {{test}} of the {{document}} {{type}} and more of the {{test}} {{document}} {{type}}")
        renderer = Renderer(template, {'test': 'ব য', 'document':'testing document', 'type':'of mine', 'bogus': 'bogus test'})
        renderer.render()

    #------------------------------------------------------------------------------
    # End profiled code
    #------------------------------------------------------------------------------
    pr.disable()
    s = StringIO.StringIO()
    sortby = 'cumulative'
    ps = pstats.Stats(pr, stream=s).sort_stats(sortby)
    ps.strip_dirs().sort_stats("time").print_stats()
    print(s.getvalue())
Ejemplo n.º 2
0
 def test_ink_renderer_render_fail_with_incorrect_delim(self):
     """Confirm that Ink renderer fails with incorrect delimiter assignment"""
     template_string = FileReader(self.template_path).read_utf8()
     standard_string = FileReader(self.standard_path).read_utf8()
     template = Template(template_string, "[[", "]]")
     renderer = Renderer(template, self.key_dictionary)
     rendered_doc = renderer.render()
     self.assertNotEqual(rendered_doc, standard_string)
Ejemplo n.º 3
0
 def test_ink_renderer_render_default_delim(self):
     """Test Ink render with default delimiters"""
     template_string = FileReader(self.template_path).read_utf8()
     standard_string = FileReader(self.standard_path).read_utf8()
     template = Template(template_string)
     renderer = Renderer(template, self.key_dictionary)
     rendered_doc = renderer.render()
     self.assertEqual(rendered_doc, standard_string)
Ejemplo n.º 4
0
	def test_ink_renderer_render_fail_with_incorrect_delim(self):
		"""Confirm that Ink renderer fails with incorrect delimiter assignment"""
		template_string = FileReader(self.template_path).read_utf8()
		standard_string = FileReader(self.standard_path).read_utf8()
		template = Template(template_string, "[[", "]]")
		renderer = Renderer(template, self.key_dictionary)
		rendered_doc = renderer.render()
		self.assertNotEqual(rendered_doc, standard_string)
Ejemplo n.º 5
0
	def test_ink_renderer_render_new_delim(self):
		"""Test Ink render with new delimiters"""
		template_string = FileReader(self.template_path2).read_utf8()
		standard_string = FileReader(self.standard_path).read_utf8()
		template = Template(template_string, "[[", "]]", escape_regex=True) # have to escape special regex chars
		renderer = Renderer(template, self.key_dictionary)
		rendered_doc = renderer.render()
		self.assertEqual(rendered_doc, standard_string)
Ejemplo n.º 6
0
	def test_ink_renderer_render_default_delim(self):
		"""Test Ink render with default delimiters"""
		template_string = FileReader(self.template_path).read_utf8()
		standard_string = FileReader(self.standard_path).read_utf8()
		template = Template(template_string)
		renderer = Renderer(template, self.key_dictionary)
		rendered_doc = renderer.render()
		self.assertEqual(rendered_doc, standard_string)
Ejemplo n.º 7
0
 def test_ink_renderer_render_new_delim(self):
     """Test Ink render with new delimiters"""
     template_string = FileReader(self.template_path2).read_utf8()
     standard_string = FileReader(self.standard_path).read_utf8()
     template = Template(
         template_string, "[[", "]]",
         escape_regex=True)  # have to escape special regex chars
     renderer = Renderer(template, self.key_dictionary)
     rendered_doc = renderer.render()
     self.assertEqual(rendered_doc, standard_string)
Ejemplo n.º 8
0
 def test_ink_renderer_new_delimiters(self):
     """Test new Ink renderer assignment of new delimiters from the template"""
     template_string = FileReader(self.template_path2).read_utf8()
     template = Template(template_string, "[[", "]]")
     renderer = Renderer(template, self.key_dictionary)
     self.assertEqual(renderer.odel, "[[")
     self.assertEqual(renderer.cdel, "]]")
Ejemplo n.º 9
0
 def test_ink_renderer_default_delimiters(self):
     """Test new Ink renderer assignment of default delimiters from the template"""
     template_string = FileReader(self.template_path).read_utf8()
     template = Template(template_string)
     renderer = Renderer(template, self.key_dictionary)
     self.assertEqual(renderer.odel, "{{")
     self.assertEqual(renderer.cdel, "}}")
Ejemplo n.º 10
0
def profile():
    #------------------------------------------------------------------------------
    # Setup a profile
    #------------------------------------------------------------------------------
    pr = cProfile.Profile()
    #------------------------------------------------------------------------------
    # Enter setup code below
    #------------------------------------------------------------------------------
    # Optional: include setup code below
    from Naked.toolshed.ink import Template, Renderer
    #------------------------------------------------------------------------------
    # Start profiler
    #------------------------------------------------------------------------------
    pr.enable()

    #------------------------------------------------------------------------------
    # Enter code to be profiled below
    #------------------------------------------------------------------------------
    # include profiled code here
    for x in range(50000):
        template = Template(
            "This is a of the {{test}} of the {{document}} {{type}} and more of the {{test}} {{document}} {{type}}"
        )
        renderer = Renderer(
            template, {
                'test': 'ব য',
                'document': 'testing document',
                'type': 'of mine',
                'bogus': 'bogus test'
            })
        renderer.render()

    #------------------------------------------------------------------------------
    # End profiled code
    #------------------------------------------------------------------------------
    pr.disable()
    s = StringIO.StringIO()
    sortby = 'cumulative'
    ps = pstats.Stats(pr, stream=s).sort_stats(sortby)
    ps.strip_dirs().sort_stats("time").print_stats()
    print(s.getvalue())
Ejemplo n.º 11
0
 def test_ink_renderer_key_dictionary(self):
     """Test new Ink renderer key_dict property"""
     template_string = FileReader(self.template_path).read_utf8()
     template = Template(template_string)
     renderer = Renderer(template, self.key_dictionary)
     self.assertEqual(renderer.key_dict, self.key_dictionary)
Ejemplo n.º 12
0
 def test_ink_renderer_template_property_string(self):
     """Test new Ink renderer template property is a string"""
     template_string = FileReader(self.template_path).read_utf8()
     template = Template(template_string)
     renderer = Renderer(template, self.key_dictionary)
     self.assertIsInstance(renderer.template, str)