Ejemplo n.º 1
0
    def test_dist_templates(self, mock_dt_path):
        base_txt = ('Line before block\n'
                    '{% block footest %}{% endblock %}\n'
                    'Line after block\n')
        dt_txt = ('{% extends ".spec" %}'
                  '{% block footest %}'
                  'foo block\n'
                  'macro: {{ py2pkg("test") }}\n'
                  '{% endblock %}')
        expected_out = ('Line before block\n'
                        'foo block\n'
                        'macro: python-test\n'
                        'Line after block')
        tmpdir = tempfile.mkdtemp(prefix='renderspec-test_')
        try:
            # create .spec template
            base_path = os.path.join(tmpdir, 'foo.spec.j2')
            with open(base_path, 'w+') as f:
                f.write(base_txt)
            # create custom dist template
            dt_dir = os.path.join(tmpdir, 'dist-templates')
            os.mkdir(dt_dir)
            dt_path = os.path.join(dt_dir, 'loldistro.spec.j2')
            with open(dt_path, 'w+') as f:
                f.write(dt_txt)
            # mock this to use testing dist-tempaltes folder
            mock_dt_path.return_value = dt_dir

            out = renderspec.generate_spec('loldistro', {}, {}, (), 'spec.j2',
                                           base_path, None)
            self.assertEqual(out, expected_out)
        finally:
            shutil.rmtree(tmpdir)
Ejemplo n.º 2
0
    def test_dist_templates(self, mock_dt_path):
        base_txt = ('Line before block\n'
                    '{% block footest %}{% endblock %}\n'
                    'Line after block\n')
        dt_txt = ('{% extends ".spec" %}'
                  '{% block footest %}'
                  'foo block\n'
                  'macro: {{ py2pkg("test") }}\n'
                  '{% endblock %}')
        expected_out = ('Line before block\n'
                        'foo block\n'
                        'macro: python-test\n'
                        'Line after block')
        tmpdir = tempfile.mkdtemp(prefix='renderspec-test_')
        try:
            # create .spec template
            base_path = os.path.join(tmpdir, 'foo.spec.j2')
            with open(base_path, 'w+') as f:
                f.write(base_txt)
            # create custom dist template
            dt_dir = os.path.join(tmpdir, 'dist-templates')
            os.mkdir(dt_dir)
            dt_path = os.path.join(dt_dir, 'loldistro.spec.j2')
            with open(dt_path, 'w+') as f:
                f.write(dt_txt)
            # mock this to use testing dist-tempaltes folder
            mock_dt_path.return_value = dt_dir

            out = renderspec.generate_spec('loldistro', {}, {}, base_path)
            self.assertEqual(out, expected_out)
        finally:
            shutil.rmtree(tmpdir)
Ejemplo n.º 3
0
 def test_generate_spec(self, template, style, epochs, requirements,
                        expected_result):
     tmpdir = tempfile.mkdtemp(prefix='renderspec-test_')
     try:
         f1 = os.path.join(tmpdir, 'test.spec.j2')
         with open(f1, 'w+') as f:
             f.write(template)
         rendered = renderspec.generate_spec(style, epochs, requirements,
                                             (), 'spec.j2', f1, None)
         self.assertTrue(rendered.endswith(expected_result))
     finally:
         shutil.rmtree(tmpdir)
Ejemplo n.º 4
0
 def test_generate_spec(self, template, style, epochs, requirements,
                        expected_result):
     tmpdir = tempfile.mkdtemp(prefix='renderspec-test_')
     try:
         f1 = os.path.join(tmpdir, 'test.spec')
         with open(f1, 'w+') as f:
             f.write(template)
         rendered = renderspec.generate_spec(
             style, epochs, requirements, f1)
         self.assertEqual(rendered, expected_result)
     finally:
         shutil.rmtree(tmpdir)