コード例 #1
0
ファイル: github.py プロジェクト: diecutter/piecutter
 def test_github_targz_error(self):
     """github_targz_content raises requests exceptions."""
     with temporary_directory() as github_mock_dir:
         archive_name = os.path.join(github_mock_dir, 'foo.tar.gz')
         self.setup_targz(archive_name, 'piecutter', 'master')
         get_mock = mock.Mock(
             side_effect=requests.exceptions.ConnectionError)
         with mock.patch('piecutter.loaders.github.requests.get',
                         new=get_mock):
             with temporary_directory() as output_dir:
                 loader = GithubLoader(output_dir)
                 self.assertRaises(
                     requests.exceptions.ConnectionError,
                     loader.github_targz_content,
                     'fake-url')
コード例 #2
0
ファイル: github.py プロジェクト: diecutter/piecutter
 def test_github_targz(self):
     """github_targz downloads and extracts archive in directory."""
     with temporary_directory() as github_mock_dir:
         archive_name = os.path.join(github_mock_dir, 'foo.tar.gz')
         self.setup_targz(archive_name, 'piecutter', 'master')
         with open(archive_name, 'r') as archive:
             content_mock = mock.Mock(return_value=archive)
             with temporary_directory() as output_dir:
                 loader = GithubLoader(output_dir)
                 loader.github_targz_content = content_mock
                 loader.github_targz('fake-user', 'piecutter', 'master')
                 self.assertTrue(
                     os.path.exists(os.path.join(output_dir,
                                                 'piecutter-master',
                                                 'greetings.txt')))
コード例 #3
0
ファイル: resources.py プロジェクト: diecutter/piecutter
 def test_render_dynamic_tree(self):
     """DirResource.render_tree() uses directory tree template."""
     content_engine = mock.MagicMock()
     content_engine.render = lambda t, c: t
     filename_engine = mock.MagicMock()
     context = {'fake': 'fake-context'}
     with temporary_directory() as template_dir:
         dir_path = template_dir
         directory_tree = [{
             'template': 'template_one.txt',
             'filename': '1.txt',
             'context': {}
         }, {
             'template': 'template_two.txt',
             'filename': '2.txt',
             'context': {}
         }]
         open(join(dir_path, resources.TREE_TEMPLATE),
              'w').write(json.dumps(directory_tree))
         dir_path += sep
         resource = resources.DirResource(path=dir_path,
                                          engine=content_engine,
                                          filename_engine=filename_engine)
         rendered = list(resource.render_tree(context))
         self.assertEqual(rendered,
                          [(unicode(join(template_dir, 'template_one.txt')),
                            u'1.txt', context),
                           (unicode(join(template_dir, 'template_two.txt')),
                            u'2.txt', context)])
     self.assertFalse(filename_engine.called)
コード例 #4
0
ファイル: resources.py プロジェクト: diecutter/piecutter
 def test_render_tree(self):
     """DirResource.render_tree() recurses nested files and directories."""
     expected_output_filename = 'rendered/{args[0]!s}'
     filename_engine = MockEngine(expected_output_filename)
     context = {'fake': 'fake-context'}
     with temporary_directory() as template_dir:
         dir_path = join(template_dir, 'dummy')
         mkdir(dir_path)
         for dir_name in ('+a+', 'b'):
             mkdir(join(dir_path, dir_name))
             for file_name in ('+one+', 'two'):
                 file_path = join(dir_path, dir_name, file_name)
                 open(file_path, 'w')
         dir_path += sep
         resource = resources.DirResource(path=dir_path,
                                          filename_engine=filename_engine)
         rendered = list(resource.render_tree(context))
         self.assertEqual(rendered,
                          [(join(template_dir, 'dummy', '+a+',
                                 '+one+'), 'rendered/+a+/+one+', context),
                           (join(template_dir, 'dummy', '+a+',
                                 'two'), 'rendered/+a+/two', context),
                           (join(template_dir, 'dummy', 'b',
                                 '+one+'), 'rendered/b/+one+', context),
                           (join(template_dir, 'dummy', 'b',
                                 'two'), 'rendered/b/two', context)])
コード例 #5
0
ファイル: resources.py プロジェクト: diecutter/piecutter
    def test_render(self):
        """DirResource.render() returns an iterable of rendered templates."""
        with temporary_directory() as template_dir:
            # Setup.
            expected_filename = 'rendered-filename/{args[0]!s}'
            filename_engine = MockEngine(expected_filename)
            expected_content = u'rendered-content/{args[0]!s}'
            content_engine = MockEngine(expected_content)
            context = {'fake': 'fake-context'}
            dir_path = join(template_dir, 'dir')
            mkdir(dir_path)
            dir_path += sep
            file_path = join(dir_path, 'file')
            open(file_path, 'w').write('data')
            resource = resources.DirResource(path=dir_path,
                                             engine=content_engine,
                                             filename_engine=filename_engine)
            # Render.
            rendered = resource.render(context)
            # Check result.
            rendered = [part for part in rendered]
            self.assertEqual(len(rendered), 1)  # One file rendered.
            self.assertEqual(len(rendered[0]), 2)  # filename, content.
            self.assertEqual(rendered[0][0], 'rendered-filename/file')

            self.assertEqual(u''.join(rendered[0][1]),
                             u'rendered-content/data')
コード例 #6
0
ファイル: github.py プロジェクト: diecutter/piecutter
 def test_github_targz_content(self):
     """github_targz_content downloads and returns archive stream."""
     with temporary_directory() as github_mock_dir:
         archive_name = os.path.join(github_mock_dir, 'foo.tar.gz')
         self.setup_targz(archive_name, 'piecutter', 'master')
         with open(archive_name, 'r') as archive:
             response_mock = mock.MagicMock()
             response_mock.raw = archive
             response_mock.status_code = 200
             get_mock = mock.Mock(return_value=response_mock)
             with mock.patch('piecutter.loaders.github.requests.get',
                             new=get_mock):
                 with temporary_directory() as output_dir:
                     loader = GithubLoader(output_dir)
                     content = loader.github_targz_content('fake-url')
                     self.assertTrue(archive is content)
コード例 #7
0
ファイル: resources.py プロジェクト: diecutter/piecutter
 def test_read_empty(self):
     """FileResource.read() empty file returns empty string."""
     with temporary_directory() as template_dir:
         path = join(template_dir, 'dummy')
         open(path, 'w')
         resource = resources.FileResource(path=path)
         self.assertEqual(resource.read(), u'')
コード例 #8
0
ファイル: resources.py プロジェクト: diecutter/piecutter
 def test_render_tree(self):
     """DirResource.render_tree() recurses nested files and directories."""
     expected_output_filename = 'rendered/{args[0]!s}'
     filename_engine = MockEngine(expected_output_filename)
     context = {'fake': 'fake-context'}
     with temporary_directory() as template_dir:
         dir_path = join(template_dir, 'dummy')
         mkdir(dir_path)
         for dir_name in ('+a+', 'b'):
             mkdir(join(dir_path, dir_name))
             for file_name in ('+one+', 'two'):
                 file_path = join(dir_path, dir_name, file_name)
                 open(file_path, 'w')
         dir_path += sep
         resource = resources.DirResource(path=dir_path,
                                          filename_engine=filename_engine)
         rendered = list(resource.render_tree(context))
         self.assertEqual(rendered,
                          [(join(template_dir, 'dummy', '+a+', '+one+'),
                            'rendered/+a+/+one+',
                            context),
                           (join(template_dir, 'dummy', '+a+', 'two'),
                            'rendered/+a+/two',
                            context),
                           (join(template_dir, 'dummy', 'b', '+one+'),
                            'rendered/b/+one+',
                            context),
                           (join(template_dir, 'dummy', 'b', 'two'),
                            'rendered/b/two',
                            context)])
コード例 #9
0
ファイル: resources.py プロジェクト: diecutter/piecutter
 def test_render_dynamic_tree(self):
     """DirResource.render_tree() uses directory tree template."""
     content_engine = mock.MagicMock()
     content_engine.render = lambda t, c: t
     filename_engine = mock.MagicMock()
     context = {'fake': 'fake-context'}
     with temporary_directory() as template_dir:
         dir_path = template_dir
         directory_tree = [{'template': 'template_one.txt',
                            'filename': '1.txt',
                            'context': {}},
                           {'template': 'template_two.txt',
                            'filename': '2.txt',
                            'context': {}}]
         open(join(dir_path, resources.TREE_TEMPLATE), 'w').write(
             json.dumps(directory_tree))
         dir_path += sep
         resource = resources.DirResource(path=dir_path,
                                          engine=content_engine,
                                          filename_engine=filename_engine)
         rendered = list(resource.render_tree(context))
         self.assertEqual(rendered,
                          [(unicode(join(template_dir, 'template_one.txt')),
                            u'1.txt',
                            context),
                           (unicode(join(template_dir, 'template_two.txt')),
                            u'2.txt',
                            context)])
     self.assertFalse(filename_engine.called)
コード例 #10
0
ファイル: resources.py プロジェクト: diecutter/piecutter
    def test_render_dynamic_tree_relative_paths(self):
        """Raises exception if directory tree contains some non relative path.

        .. warning::

           This is a security test!

           Since dynamic tree templates can be defined by user, we have to
           check templates path. We don't want users to be able to render
           arbitrary locations on the filesystem.

        """
        content_engine = mock.MagicMock()
        content_engine.render = lambda t, c: t
        filename_engine = mock.MagicMock()
        context = {'fake': 'fake-context'}
        with temporary_directory() as template_dir:
            dir_path = template_dir
            directory_tree = [{'template': '../template_one.txt',
                               'filename': '1.txt',
                               'context': {}}]
            open(join(dir_path, resources.TREE_TEMPLATE), 'w').write(
                json.dumps(directory_tree))
            dir_path += sep
            resource = resources.DirResource(path=dir_path,
                                             engine=content_engine,
                                             filename_engine=filename_engine)
            generate_content = lambda: [(filename, ''.join(content))
                                        for (filename, content)
                                        in resource.render(context)]
            self.assertRaises(ValueError, generate_content)
        self.assertFalse(filename_engine.called)
コード例 #11
0
ファイル: resources.py プロジェクト: diecutter/piecutter
    def test_render(self):
        """DirResource.render() returns an iterable of rendered templates."""
        with temporary_directory() as template_dir:
            # Setup.
            expected_filename = 'rendered-filename/{args[0]!s}'
            filename_engine = MockEngine(expected_filename)
            expected_content = u'rendered-content/{args[0]!s}'
            content_engine = MockEngine(expected_content)
            context = {'fake': 'fake-context'}
            dir_path = join(template_dir, 'dir')
            mkdir(dir_path)
            dir_path += sep
            file_path = join(dir_path, 'file')
            open(file_path, 'w').write('data')
            resource = resources.DirResource(path=dir_path,
                                             engine=content_engine,
                                             filename_engine=filename_engine)
            # Render.
            rendered = resource.render(context)
            # Check result.
            rendered = [part for part in rendered]
            self.assertEqual(len(rendered), 1)  # One file rendered.
            self.assertEqual(len(rendered[0]), 2)  # filename, content.
            self.assertEqual(rendered[0][0], 'rendered-filename/file')

            self.assertEqual(u''.join(rendered[0][1]),
                             u'rendered-content/data')
コード例 #12
0
ファイル: resources.py プロジェクト: diecutter/piecutter
 def test_read_empty(self):
     """FileResource.read() empty file returns empty string."""
     with temporary_directory() as template_dir:
         path = join(template_dir, 'dummy')
         open(path, 'w')
         resource = resources.FileResource(path=path)
         self.assertEqual(resource.read(), u'')
コード例 #13
0
ファイル: github.py プロジェクト: diecutter/piecutter
 def test_github_targz_content_not_found(self):
     """github_targz_content raises NotFound if Github returns 404."""
     with temporary_directory() as github_mock_dir:
         archive_name = os.path.join(github_mock_dir, 'foo.tar.gz')
         self.setup_targz(archive_name, 'piecutter', 'master')
         response_mock = mock.MagicMock()
         response_mock.status_code = 404
         get_mock = mock.Mock(return_value=response_mock)
         with mock.patch('piecutter.loaders.github.requests.get',
                         new=get_mock):
             with temporary_directory() as output_dir:
                 loader = GithubLoader(output_dir)
                 self.assertRaises(
                     piecutter.exceptions.TemplateNotFound,
                     loader.github_targz_content,
                     'fake-url')
コード例 #14
0
ファイル: resources.py プロジェクト: diecutter/piecutter
    def test_render_dynamic_tree_relative_paths(self):
        """Raises exception if directory tree contains some non relative path.

        .. warning::

           This is a security test!

           Since dynamic tree templates can be defined by user, we have to
           check templates path. We don't want users to be able to render
           arbitrary locations on the filesystem.

        """
        content_engine = mock.MagicMock()
        content_engine.render = lambda t, c: t
        filename_engine = mock.MagicMock()
        context = {'fake': 'fake-context'}
        with temporary_directory() as template_dir:
            dir_path = template_dir
            directory_tree = [{
                'template': '../template_one.txt',
                'filename': '1.txt',
                'context': {}
            }]
            open(join(dir_path, resources.TREE_TEMPLATE),
                 'w').write(json.dumps(directory_tree))
            dir_path += sep
            resource = resources.DirResource(path=dir_path,
                                             engine=content_engine,
                                             filename_engine=filename_engine)
            generate_content = lambda: [(filename, ''.join(content)) for (
                filename, content) in resource.render(context)]
            self.assertRaises(ValueError, generate_content)
        self.assertFalse(filename_engine.called)
コード例 #15
0
ファイル: resources.py プロジェクト: diecutter/piecutter
 def test_has_tree_template(self):
     """DirResource.has_tree_template() checks if directory tree exists."""
     with temporary_directory() as template_dir:
         dir_path = template_dir
         resource = resources.DirResource(path=dir_path)
         self.assertFalse(resource.has_tree_template())
         open(join(dir_path, resources.TREE_TEMPLATE), 'w')
         self.assertTrue(resource.has_tree_template())
コード例 #16
0
ファイル: resources.py プロジェクト: diecutter/piecutter
 def test_read_utf8(self):
     """FileResource.read() decodes UTF-8 files."""
     with temporary_directory() as template_dir:
         path = join(template_dir, 'dummy')
         content = u'Thé ou café ?'
         open(path, 'w').write(content.encode('utf8'))
         resource = resources.FileResource(path=path)
         self.assertEqual(resource.read(), content)
コード例 #17
0
ファイル: resources.py プロジェクト: diecutter/piecutter
 def test_exists_file(self):
     """FileResource.exists is True if path points a file."""
     with temporary_directory() as template_dir:
         path = join(template_dir, 'dummy')
         open(path, 'w')
         self.assertTrue(isfile(path))  # Check initial status.
         resource = resources.FileResource(path=path)
         self.assertTrue(resource.exists is True)
コード例 #18
0
ファイル: resources.py プロジェクト: diecutter/piecutter
 def test_has_tree_template(self):
     """DirResource.has_tree_template() checks if directory tree exists."""
     with temporary_directory() as template_dir:
         dir_path = template_dir
         resource = resources.DirResource(path=dir_path)
         self.assertFalse(resource.has_tree_template())
         open(join(dir_path, resources.TREE_TEMPLATE), 'w')
         self.assertTrue(resource.has_tree_template())
コード例 #19
0
ファイル: resources.py プロジェクト: diecutter/piecutter
 def test_exists_dir(self):
     """FileResource.exists is False if path points a directory."""
     with temporary_directory() as template_dir:
         path = join(template_dir, 'dummy')
         mkdir(path)
         self.assertTrue(isdir(path))  # Check initial status.
         resource = resources.FileResource(path=path)
         self.assertTrue(resource.exists is False)
コード例 #20
0
ファイル: resources.py プロジェクト: diecutter/piecutter
 def test_read_utf8(self):
     """FileResource.read() decodes UTF-8 files."""
     with temporary_directory() as template_dir:
         path = join(template_dir, 'dummy')
         content = u'Thé ou café ?'
         open(path, 'w').write(content.encode('utf8'))
         resource = resources.FileResource(path=path)
         self.assertEqual(resource.read(), content)
コード例 #21
0
ファイル: resources.py プロジェクト: diecutter/piecutter
 def test_exists_dir(self):
     """FileResource.exists is False if path points a directory."""
     with temporary_directory() as template_dir:
         path = join(template_dir, 'dummy')
         mkdir(path)
         self.assertTrue(isdir(path))  # Check initial status.
         resource = resources.FileResource(path=path)
         self.assertTrue(resource.exists is False)
コード例 #22
0
ファイル: resources.py プロジェクト: diecutter/piecutter
 def test_exists_file(self):
     """FileResource.exists is True if path points a file."""
     with temporary_directory() as template_dir:
         path = join(template_dir, 'dummy')
         open(path, 'w')
         self.assertTrue(isfile(path))  # Check initial status.
         resource = resources.FileResource(path=path)
         self.assertTrue(resource.exists is True)
コード例 #23
0
ファイル: resources.py プロジェクト: diecutter/piecutter
 def test_no_trailing_slash(self):
     """DirResource with no trailing slash uses dirname as prefix."""
     with temporary_directory() as template_dir:
         dir_path = join(template_dir, 'dummy')
         mkdir(dir_path)
         file_path = join(dir_path, 'one')
         open(file_path, 'w')
         resource = resources.DirResource(path=dir_path)
         self.assertEqual(resource.read(), 'dummy/one')
コード例 #24
0
ファイル: resources.py プロジェクト: diecutter/piecutter
 def test_no_trailing_slash(self):
     """DirResource with no trailing slash uses dirname as prefix."""
     with temporary_directory() as template_dir:
         dir_path = join(template_dir, 'dummy')
         mkdir(dir_path)
         file_path = join(dir_path, 'one')
         open(file_path, 'w')
         resource = resources.DirResource(path=dir_path)
         self.assertEqual(resource.read(), 'dummy/one')
コード例 #25
0
ファイル: resources.py プロジェクト: diecutter/piecutter
 def test_read_one_flat(self):
     """DirResource.read() one file returns one filename."""
     with temporary_directory() as template_dir:
         dir_path = join(template_dir, 'dummy')
         mkdir(dir_path)
         file_path = join(dir_path, 'one')
         open(file_path, 'w')
         dir_path += sep
         resource = resources.DirResource(path=dir_path)
         self.assertEqual(resource.read(), 'one')
コード例 #26
0
ファイル: resources.py プロジェクト: diecutter/piecutter
 def test_read_one_flat(self):
     """DirResource.read() one file returns one filename."""
     with temporary_directory() as template_dir:
         dir_path = join(template_dir, 'dummy')
         mkdir(dir_path)
         file_path = join(dir_path, 'one')
         open(file_path, 'w')
         dir_path += sep
         resource = resources.DirResource(path=dir_path)
         self.assertEqual(resource.read(), 'one')
コード例 #27
0
ファイル: resources.py プロジェクト: diecutter/piecutter
 def test_render_error(self):
     """FileResource.render() raises ``TemplateError`` in case of fail."""
     with temporary_directory() as template_dir:
         path = join(template_dir, 'dummy')
         template = u'Tea or coffee'
         context = {'a': 1, 'b': 2}
         engine = MockEngine(fail=TemplateError('This is an error message'))
         open(path, 'w').write(template.encode('utf8'))
         resource = resources.FileResource(path=path, engine=engine)
         self.assertRaises(TemplateError, resource.render, context)
コード例 #28
0
ファイル: resources.py プロジェクト: diecutter/piecutter
 def test_render_error(self):
     """FileResource.render() raises ``TemplateError`` in case of fail."""
     with temporary_directory() as template_dir:
         path = join(template_dir, 'dummy')
         template = u'Tea or coffee'
         context = {'a': 1, 'b': 2}
         engine = MockEngine(fail=TemplateError('This is an error message'))
         open(path, 'w').write(template.encode('utf8'))
         resource = resources.FileResource(path=path, engine=engine)
         self.assertRaises(TemplateError, resource.render, context)
コード例 #29
0
ファイル: resources.py プロジェクト: diecutter/piecutter
 def test_read_two_flat(self):
     """DirResource.read() two files returns two filenames."""
     with temporary_directory() as template_dir:
         dir_path = join(template_dir, 'dummy')
         mkdir(dir_path)
         for file_name in ('one', 'two'):
             file_path = join(dir_path, file_name)
             open(file_path, 'w')
         dir_path += sep
         resource = resources.DirResource(path=dir_path)
         self.assertEqual(resource.read(), "one\ntwo")
コード例 #30
0
ファイル: resources.py プロジェクト: diecutter/piecutter
 def test_read_two_flat(self):
     """DirResource.read() two files returns two filenames."""
     with temporary_directory() as template_dir:
         dir_path = join(template_dir, 'dummy')
         mkdir(dir_path)
         for file_name in ('one', 'two'):
             file_path = join(dir_path, file_name)
             open(file_path, 'w')
         dir_path += sep
         resource = resources.DirResource(path=dir_path)
         self.assertEqual(resource.read(), "one\ntwo")
コード例 #31
0
ファイル: resources.py プロジェクト: diecutter/piecutter
 def test_read_nested(self):
     """DirResource.read() recurses nested files and directories."""
     with temporary_directory() as template_dir:
         dir_path = join(template_dir, 'dummy')
         mkdir(dir_path)
         for dir_name in ('a', 'b'):
             mkdir(join(dir_path, dir_name))
             for file_name in ('one', 'two'):
                 file_path = join(dir_path, dir_name, file_name)
                 open(file_path, 'w')
         dir_path += sep
         resource = resources.DirResource(path=dir_path)
         self.assertEqual(resource.read(), "a/one\na/two\nb/one\nb/two")
コード例 #32
0
ファイル: resources.py プロジェクト: diecutter/piecutter
 def test_read_nested(self):
     """DirResource.read() recurses nested files and directories."""
     with temporary_directory() as template_dir:
         dir_path = join(template_dir, 'dummy')
         mkdir(dir_path)
         for dir_name in ('a', 'b'):
             mkdir(join(dir_path, dir_name))
             for file_name in ('one', 'two'):
                 file_path = join(dir_path, dir_name, file_name)
                 open(file_path, 'w')
         dir_path += sep
         resource = resources.DirResource(path=dir_path)
         self.assertEqual(resource.read(),
                          "a/one\na/two\nb/one\nb/two")
コード例 #33
0
ファイル: resources.py プロジェクト: diecutter/piecutter
    def test_render(self):
        """FileResource.render() generates rendered template against context.

        It returns an iteratable or generator.

        """
        with temporary_directory() as template_dir:
            path = join(template_dir, 'dummy')
            template = u'Tea or coffee'
            context = {'a': 1, 'b': 2}
            engine = MockEngine(u'this is render result')
            open(path, 'w').write(template.encode('utf8'))
            resource = resources.FileResource(path=path, engine=engine)
            result = resource.render(context)
            result = ''.join(result)
            self.assertEqual(result, u'this is render result')
            self.assertEqual(engine.args, (template, context))
            self.assertEqual(engine.kwargs, {})
コード例 #34
0
ファイル: resources.py プロジェクト: diecutter/piecutter
    def test_render(self):
        """FileResource.render() generates rendered template against context.

        It returns an iteratable or generator.

        """
        with temporary_directory() as template_dir:
            path = join(template_dir, 'dummy')
            template = u'Tea or coffee'
            context = {'a': 1, 'b': 2}
            engine = MockEngine(u'this is render result')
            open(path, 'w').write(template.encode('utf8'))
            resource = resources.FileResource(path=path, engine=engine)
            result = resource.render(context)
            result = ''.join(result)
            self.assertEqual(result, u'this is render result')
            self.assertEqual(engine.args, (template, context))
            self.assertEqual(engine.kwargs, {})
コード例 #35
0
ファイル: resources.py プロジェクト: diecutter/piecutter
 def test_render_template_error(self):
     with temporary_directory() as template_dir:
         # Setup.
         expected_filename = 'rendered-filename/{args[0]!s}'
         filename_engine = MockEngine(expected_filename)
         content_engine = MockEngine(fail=TemplateError('error!'))
         context = {'fake': 'fake-context'}
         dir_path = join(template_dir, 'dir')
         mkdir(dir_path)
         dir_path += sep
         file_path = join(dir_path, 'file')
         open(file_path, 'w').write('data')
         resource = resources.DirResource(path=dir_path,
                                          engine=content_engine,
                                          filename_engine=filename_engine)
         # Render.
         generate_content = lambda: [(filename, ''.join(content)) for (
             filename, content) in resource.render(context)]
         self.assertRaises(TemplateError, generate_content)
コード例 #36
0
ファイル: resources.py プロジェクト: diecutter/piecutter
 def test_render_template_error(self):
     with temporary_directory() as template_dir:
         # Setup.
         expected_filename = 'rendered-filename/{args[0]!s}'
         filename_engine = MockEngine(expected_filename)
         content_engine = MockEngine(fail=TemplateError('error!'))
         context = {'fake': 'fake-context'}
         dir_path = join(template_dir, 'dir')
         mkdir(dir_path)
         dir_path += sep
         file_path = join(dir_path, 'file')
         open(file_path, 'w').write('data')
         resource = resources.DirResource(path=dir_path,
                                          engine=content_engine,
                                          filename_engine=filename_engine)
         # Render.
         generate_content = lambda: [(filename, ''.join(content))
                                     for (filename, content)
                                     in resource.render(context)]
         self.assertRaises(TemplateError, generate_content)
コード例 #37
0
ファイル: resources.py プロジェクト: diecutter/piecutter
 def test_read_empty(self):
     """DirResource.read() empty dir returns empty string."""
     with temporary_directory() as path:
         resource = resources.DirResource(path=path)
         self.assertEqual(resource.read(), u'')
コード例 #38
0
ファイル: github.py プロジェクト: adamchainz/diecutter
 def post(self, request):
     with temporary_directory() as checkout_dir:
         self.checkout_dir = checkout_dir
         return super(GithubService, self).post(request)
コード例 #39
0
ファイル: github.py プロジェクト: diecutter/diecutter
 def post(self, request):
     with temporary_directory() as checkout_dir:
         self.checkout_dir = checkout_dir
         return super(GithubService, self).post(request)
コード例 #40
0
ファイル: resources.py プロジェクト: diecutter/piecutter
 def test_read_empty(self):
     """DirResource.read() empty dir returns empty string."""
     with temporary_directory() as path:
         resource = resources.DirResource(path=path)
         self.assertEqual(resource.read(), u'')