Ejemplo n.º 1
0
    def test_different_output_name(self):
        tpl_filename = os.path.join(self.scratch_dir, 'file1.tpl')
        output_filename = os.path.join(self.scratch_dir, 'file2')

        with open(tpl_filename, 'w') as f:
            f.write('foo')

        envtpl.process_file(tpl_filename, output_filename, {}, False, True)
        with open(output_filename, 'r') as f:
            self.assertEquals(f.read(), 'foo')

        self.assertFalse(os.path.exists(tpl_filename))
Ejemplo n.º 2
0
    def test_different_output_name(self):
        tpl_filename = os.path.join(self.scratch_dir, 'file1.tpl')
        output_filename = os.path.join(self.scratch_dir, 'file2')

        with open(tpl_filename, 'w') as f:
            f.write('foo')

        envtpl.process_file(tpl_filename, output_filename, {}, False, True)
        with open(output_filename, 'r') as f:
            self.assertEquals(f.read(), 'foo')

        self.assertFalse(os.path.exists(tpl_filename))
Ejemplo n.º 3
0
    def test_no_delete(self):
        filename = os.path.join(self.scratch_dir, 'file1')
        tpl_filename = filename + '.tpl'

        with open(tpl_filename, 'w') as f:
            f.write('foo')

        envtpl.process_file(tpl_filename, None, {'FOO': '---', 'BAR': '+++'}, False, False)
        with open(filename, 'r') as f:
            self.assertEquals(f.read(), 'foo')

        self.assertTrue(os.path.exists(tpl_filename))
Ejemplo n.º 4
0
    def test_no_delete(self):
        filename = os.path.join(self.scratch_dir, 'file1')
        tpl_filename = filename + '.tpl'

        with open(tpl_filename, 'w') as f:
            f.write('foo')

        envtpl.process_file(tpl_filename, None, {'FOO': '---', 'BAR': '+++'}, False, False, '{{,}}')
        with open(filename, 'r') as f:
            self.assertEquals(f.read(), 'foo')

        self.assertTrue(os.path.exists(tpl_filename))
Ejemplo n.º 5
0
    def test_environment_vars(self):
        filename = os.path.join(self.scratch_dir, 'file1')
        tpl_filename = filename + '.tpl'

        with open(tpl_filename, 'w') as f:
            f.write('''abc {{ FOO }} 123
frogs will be frogs
{{    BAR|default("456")}}''')

        expected = '''abc --- 123
frogs will be frogs
+++'''
        envtpl.process_file(tpl_filename, None, {'FOO': '---', 'BAR': '+++'}, False, True)
        with open(filename, 'r') as f:
            self.assertEquals(f.read(), expected)
Ejemplo n.º 6
0
    def test_environment_vars(self):
        filename = os.path.join(self.scratch_dir, 'file1')
        tpl_filename = filename + '.tpl'

        with open(tpl_filename, 'w') as f:
            f.write('''abc {{ FOO }} 123
frogs will be frogs
{{    BAR|default("456")}}''')

        expected = '''abc --- 123
frogs will be frogs
+++'''
        envtpl.process_file(tpl_filename, None, {'FOO': '---', 'BAR': '+++'}, False, True, '{{,}}')
        with open(filename, 'r') as f:
            self.assertEquals(f.read(), expected)
Ejemplo n.º 7
0
    def test_delete(self):
        filename = os.path.join(self.scratch_dir, 'file1')
        tpl_filename = filename + '.tpl'

        with open(tpl_filename, 'w') as f:
            f.write('''abc {{ FOO }} 123
frogs will be frogs
{{    BAR | default("456")}}''')

        expected = '''abc  123
frogs will be frogs
456'''
        envtpl.process_file(tpl_filename, None, {}, False, True)
        with open(filename, 'r') as f:
            self.assertEquals(f.read(), expected)

        self.assertFalse(os.path.exists(tpl_filename))
Ejemplo n.º 8
0
    def test_delete(self):
        filename = os.path.join(self.scratch_dir, 'file1')
        tpl_filename = filename + '.tpl'

        with open(tpl_filename, 'w') as f:
            f.write('''abc {{ FOO }} 123
frogs will be frogs
{{    BAR | default("456")}}''')

        expected = '''abc  123
frogs will be frogs
456'''
        envtpl.process_file(tpl_filename, None, {}, False, True)
        with open(filename, 'r') as f:
            self.assertEquals(f.read(), expected)

        self.assertFalse(os.path.exists(tpl_filename))
Ejemplo n.º 9
0
    def test_include(self):
        filename = os.path.join(self.scratch_dir, 'file1')
        incl_filename = filename + "-incl.tpl"
        tpl_filename = filename + '.tpl'

        with open(incl_filename, 'w') as f:
            f.write('''{{ INCLUDE|default('incl') }}''')

        with open(tpl_filename, 'w') as f:
            f.write('''abc {{ FOO }} 123 {% include 'file1-incl.tpl' %}
frogs will be frogs
{{    BAR|default("456")}}''')

        expected = '''abc --- 123 incl
frogs will be frogs
+++'''
        envtpl.process_file(tpl_filename, None, {'FOO': '---', 'BAR': '+++'}, False, True)
        with open(filename, 'r') as f:
            self.assertEquals(f.read(), expected)
Ejemplo n.º 10
0
    def test_include(self):
        filename = os.path.join(self.scratch_dir, 'file1')
        incl_filename = filename + "-incl.tpl"
        tpl_filename = filename + '.tpl'

        with open(incl_filename, 'w') as f:
            f.write('''{{ INCLUDE|default('incl') }}''')

        with open(tpl_filename, 'w') as f:
            f.write('''abc {{ FOO }} 123 {% include 'file1-incl.tpl' %}
frogs will be frogs
{{    BAR|default("456")}}''')

        expected = '''abc --- 123 incl
frogs will be frogs
+++'''
        envtpl.process_file(tpl_filename, None, {'FOO': '---', 'BAR': '+++'}, False, True, '{{,}}')
        with open(filename, 'r') as f:
            self.assertEquals(f.read(), expected)