Example #1
0
    def test_sites_generation(self):
        '''Test generation of sites with the plugin

        Compare with recorded output via ``git diff``.
        To generate output for comparison run the command
        ``pelican -o test_data/output -s test_data/pelicanconf.py \
        test_data/content``
        Remember to remove the output/ folder before that.
        '''
        base_path = os.path.dirname(os.path.abspath(__file__))
        base_path = os.path.join(base_path, 'test_data')
        content_path = os.path.join(base_path, 'content')
        output_path = os.path.join(base_path, 'output')
        settings_path = os.path.join(base_path, 'pelicanconf.py')
        settings = read_settings(path=settings_path, override={
            'PATH': content_path,
            'OUTPUT_PATH': self.temp_path,
            'CACHE_PATH': self.temp_cache,
            'PLUGINS': [i18ns],
            }
        )
        pelican = Pelican(settings)
        pelican.run()

        # compare output
        out, err = subprocess.Popen(
            ['git', 'diff', '--no-ext-diff', '--exit-code', '-w', output_path,
             self.temp_path], env={'PAGER': ''},
            stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()
        self.assertFalse(out, 'non-empty `diff` stdout:\n{}'.format(out))
        self.assertFalse(err, 'non-empty `diff` stderr:\n{}'.format(err))
Example #2
0
    def setUp(self, override=None):
        self.output_path = mkdtemp(prefix=TEST_DIR_PREFIX)
        self.content_path = mkdtemp(prefix=TEST_DIR_PREFIX)
        settings = {
            'PATH': self.content_path,
            'OUTPUT_PATH': self.output_path,
            'PLUGINS': [linkclass],
            'CACKHE_CONTENT': False,
            'LINKCLASS_INTERNAL_CLASS': INTERNAL_CLASS,
            'LINKCLASS_EXTERNAL_CLASS': EXTERNAL_CLASS
        }
        if override:
            settings.update(override)

        ## Generate the test Markdown source file
        fid = open(os.path.join(self.content_path, '%s.md' % TEST_FILE_STEM),
                   'w')
        fid.write('''Title: Test
Date:

[%s](%s)

[%s](%s)

[%s](%s)
''' % (INTERNAL_TEXT, INTERNAL_LINK, EXTERNAL_TEXT, EXTERNAL_LINK_HTTP,
        EXTERNAL_TEXT, EXTERNAL_LINK_HTTPS))
        fid.close()

        ## Run teh Pelican instance
        self.settings = read_settings(override=settings)
        pelican = Pelican(settings=self.settings)
        pelican.run()
Example #3
0
 def run_pelican(self, settings):
     implicit_settings = {
         # Contains just stuff that isn't required by the m.css theme itself,
         # but is needed to have the test setup working correctly
         'RELATIVE_URLS': True,
         'TIMEZONE': 'UTC',
         'READERS': {'html': None},
         'SITEURL': '.',
         'PATH': os.path.join(self.path),
         'OUTPUT_PATH': os.path.join(self.path, 'output'),
         'PAGE_PATHS': [''],
         'PAGE_SAVE_AS': '{slug}.html',
         'PAGE_URL': '{slug}.html',
         'PAGE_EXCLUDES': ['output'],
         'ARTICLE_PATHS': ['articles'], # does not exist
         # Don't render feeds, we don't want to test them all the time
         'FEED_ALL_ATOM': None,
         'CATEGORY_FEED_ATOM': None,
         'THEME': '../pelican-theme',
         'PLUGIN_PATHS': ['.'],
         'THEME_STATIC_DIR': 'static',
         'M_CSS_FILES': ['https://fonts.googleapis.com/css?family=Source+Sans+Pro:400,400i,600,600i',
            'static/m-dark.css'],
         'M_FINE_PRINT': None,
         'M_DISABLE_SOCIAL_META_TAGS': True,
         'DIRECT_TEMPLATES': [],
         'SLUGIFY_SOURCE': 'basename'
     }
     implicit_settings.update(settings)
     settings = read_settings(path=None, override=implicit_settings)
     pelican = Pelican(settings=settings)
     pelican.run()
Example #4
0
 def test_custom_generation_works(self):
     # the same thing with a specified set of settings should work
     pelican = Pelican(path=INPUT_PATH, output_path=self.temp_path,
                         settings=read_settings(SAMPLE_CONFIG))
     pelican.run()
     diff = dircmp(self.temp_path, os.sep.join((OUTPUT_PATH, "custom")))
     self.assertFilesEqual(diff)
Example #5
0
    def test_generic_tag_with_config(self):
        """Test generation of site with a generic tag that reads in a config file."""

        base_path = os.path.dirname(os.path.abspath(__file__))
        base_path = os.path.join(base_path, "test_data")
        content_path = os.path.join(base_path, "content")
        output_path = os.path.join(base_path, "output")
        settings_path = os.path.join(base_path, "pelicanconf.py")
        settings = read_settings(
            path=settings_path,
            override={
                "PATH": content_path,
                "OUTPUT_PATH": self.temp_path,
                "CACHE_PATH": self.temp_cache,
            },
        )

        pelican = Pelican(settings)
        pelican.run()

        assert os.path.exists(
            os.path.join(self.temp_path, "test-generic-config-tag.html"))

        assert ("Tester" in open(
            os.path.join(self.temp_path,
                         "test-generic-config-tag.html")).read())
Example #6
0
 def run_pelican(self, settings):
     implicit_settings = {
         # Contains just stuff that isn't required by the m.css theme itself,
         # but is needed to have the test setup working correctly
         'RELATIVE_URLS': True,
         'TIMEZONE': 'UTC',
         'READERS': {'html': None},
         'SITEURL': '.',
         'PATH': os.path.join(self.path),
         'OUTPUT_PATH': os.path.join(self.path, 'output'),
         'PAGE_PATHS': [''],
         'PAGE_SAVE_AS': '{slug}.html',
         'PAGE_URL': '{slug}.html',
         'PAGE_EXCLUDES': ['output'],
         'ARTICLE_PATHS': ['articles'], # does not exist
         'FEED_ALL_ATOM': None, # Don't render feeds, we're not testing them *ever*
         'THEME': '../pelican-theme',
         'PLUGIN_PATHS': ['.'],
         'THEME_STATIC_DIR': 'static',
         'M_CSS_FILES': ['https://fonts.googleapis.com/css?family=Source+Sans+Pro:400,400i,600,600i',
            'static/m-dark.css'],
         'M_FINE_PRINT': None,
         'M_DISABLE_SOCIAL_META_TAGS': True,
         'DIRECT_TEMPLATES': [],
         'SLUGIFY_SOURCE': 'basename'
     }
     implicit_settings.update(settings)
     settings = read_settings(path=None, override=implicit_settings)
     pelican = Pelican(settings=settings)
     pelican.run()
    def setUp (self, override = None):
        self.output_path = mkdtemp (prefix = TEST_DIR_PREFIX)
        self.content_path = mkdtemp (prefix = TEST_DIR_PREFIX)
        settings = {
            'PATH': self.content_path,
            'OUTPUT_PATH': self.output_path,
            'PLUGINS': [linkclass],
            'CACKHE_CONTENT': False,
            'LINKCLASS_INTERNAL_CLASS': INTERNAL_CLASS,
            'LINKCLASS_EXTERNAL_CLASS': EXTERNAL_CLASS
        }
        if override:
            settings.update (override)

        ## Generate the test Markdown source file
        fid = open (os.path.join (self.content_path, '%s.md' % TEST_FILE_STEM),
                    'w')
        fid.write ('''Title: Test
Date:

[%s](%s)

[%s](%s)

[%s](%s)
''' % (INTERNAL_TEXT, INTERNAL_LINK,
       EXTERNAL_TEXT, EXTERNAL_LINK_HTTP,
       EXTERNAL_TEXT, EXTERNAL_LINK_HTTPS))
        fid.close ()

        ## Run teh Pelican instance
        self.settings = read_settings (override = settings)
        pelican = Pelican (settings = self.settings)
        pelican.run ()
Example #8
0
    def test_generic_alt_delimiters(self):
        '''Test generation of site with alternatively delimited tags.'''

        _pj = os.path.join
        base_path = _pj(os.path.dirname(os.path.abspath(__file__)), 'test_data')
        content_path = _pj(base_path, 'content')
        output_path = _pj(base_path, 'output')
        settings_path = _pj(base_path, 'pelicanconf.py')
        override = {
                'PATH': content_path,
                'OUTPUT_PATH': self.temp_path,
                'CACHE_PATH': self.temp_cache,
                'LT_DELIMITERS': ('<+', '+>'),
        }
        settings = read_settings(path=settings_path, override=override)

        pelican = Pelican(settings)
        pelican.run()

        # test alternate delimiters
        f = _pj(self.temp_path, 'test-alternate-tag-delimiters.html')
        fc = open(f).read()
        assert '{% generic config author %} is stupid' in fc
        assert 'The Tester is smart' in fc
        assert 'The Tester is stupid' not in fc
Example #9
0
    def test_generic_tag_with_config(self):
        '''Test generation of site with a generic tag that reads in a config file.'''

        _pj = os.path.join
        base_path = _pj(os.path.dirname(os.path.abspath(__file__)), 'test_data')
        content_path = _pj(base_path, 'content')
        output_path = _pj(base_path, 'output')
        settings_path = _pj(base_path, 'pelicanconf.py')
        override = {
                'PATH': content_path,
                'OUTPUT_PATH': self.temp_path,
                'CACHE_PATH': self.temp_cache,
        }
        settings = read_settings(path=settings_path, override=override)

        pelican = Pelican(settings)
        pelican.run()

        # test normal tags
        f = _pj(self.temp_path, 'test-generic-config-tag.html')
        assert os.path.exists(f)
        assert "Tester" in open(f).read()

        # test differences
        f1 = _pj(output_path, 'test-ipython-notebook-v3.html')
        f2 = _pj(self.temp_path, 'test-ipython-notebook.html')
    def setUp(self, settings_overrides=None, count=5,
              categories_per_content=1, categories=None):
        self.temp_input_dir = tempfile.mkdtemp(prefix="cc-input-")
        page_directory = os.path.join(self.temp_input_dir, 'pages')
        os.mkdir(page_directory)
        self.temp_output_dir = tempfile.mkdtemp(prefix="cc-output-")

        if categories is None:
            categories = [get_random_text_and_whitespace() for _ in range(5)]

        self.articles = make_content(
            self.temp_input_dir, categories, count=count,
            categories_per_content=categories_per_content)
        self.pages = make_content(
            page_directory, categories, count=count,
            categories_per_content=categories_per_content)
        settings = {
            'PATH': self.temp_input_dir,
            'PAGE_DIR': 'pages',
            'OUTPUT_PATH': self.temp_output_dir,
            'PLUGINS': [cc],
            'DEFAULT_DATE': (2014, 6, 8),
            }
        if settings_overrides is not None:
            settings.update(settings_overrides)
        settings = read_settings(override=settings)
        pelican = Pelican(settings=settings)
        pelican.modified_run = modified_pelican_run
        self.collations = pelican.modified_run(pelican)['collations']
Example #11
0
def compile():
    settings = get_settings()
    p = Pelican(settings)
    try:
        p.run()
    except SystemExit as e:
        pass
Example #12
0
 def test_custom_generation_works(self):
     # the same thing with a specified set of settings should work
     settings = read_settings(filename=SAMPLE_CONFIG, override={"PATH": INPUT_PATH, "OUTPUT_PATH": self.temp_path})
     pelican = Pelican(settings=settings)
     pelican.run()
     dcmp = dircmp(self.temp_path, os.sep.join((OUTPUT_PATH, "custom")))
     self.assertFilesEqual(recursiveDiff(dcmp))
Example #13
0
 def testKnitrSettings2(self):
     settings = read_settings(path=None, override={
         'LOAD_CONTENT_CACHE': False,
         'PATH': self.contentdir,
         'OUTPUT_PATH': self.outputdir,
         'RMD_READER_KNITR_OPTS_CHUNK': {'fig.path' : '%s/' % self.figpath},
         'RMD_READER_KNITR_OPTS_KNIT': {'progress' : True, 'verbose': True},
         'RMD_READER_RENAME_PLOT': True,
         'PLUGIN_PATHS': ['../'],
         'PLUGINS': ['rmd_reader'],
     })
     pelican = Pelican(settings=settings)
     pelican.run()
     
     outputfilename = os.path.join(self.outputdir,'%s.html' % self.testtitle)
     self.assertTrue(os.path.exists(outputfilename),'File %s was not created.' % outputfilename)
     
     imagesdir = os.path.join(self.outputdir, self.figpath)
     self.assertTrue(os.path.exists(imagesdir), 'figpath not created.')
     
     imagefile = os.path.join(imagesdir, os.path.splitext(os.path.split(self.contentfile)[1])[0]) + '-1-1.png'
     logging.debug(imagefile)
     self.assertTrue(os.path.exists(imagefile), 'image correctly named.')
     
     images = glob.glob('%s/*' % imagesdir)
     logging.debug(images)
     self.assertTrue(len(images) == 1,'Contents of images dir is not correct: %s' % ','.join(images))
Example #14
0
    def setUp(self, settings_overrides=None, count=5,
              categories_per_content=1, categories=None):
        self.temp_input_dir = tempfile.mkdtemp(prefix="cc-input-")
        page_directory = os.path.join(self.temp_input_dir, 'pages')
        os.mkdir(page_directory)
        self.temp_output_dir = tempfile.mkdtemp(prefix="cc-output-")

        if categories is None:
            categories = [get_random_text_and_whitespace() for _ in range(5)]

        self.articles = make_content(
            self.temp_input_dir, categories, count=count,
            categories_per_content=categories_per_content)
        self.pages = make_content(
            page_directory, categories, count=count,
            categories_per_content=categories_per_content)
        settings = {
            'PATH': self.temp_input_dir,
            'PAGE_DIR': 'pages',
            'OUTPUT_PATH': self.temp_output_dir,
            'PLUGINS': [cc],
            'DEFAULT_DATE': (2014, 6, 8),
            }
        if settings_overrides is not None:
            settings.update(settings_overrides)
        settings = read_settings(override=settings)
        pelican = Pelican(settings=settings)
        pelican.modified_run = modified_pelican_run
        self.collations = pelican.modified_run(pelican)['collations']
    def setUp(self, override=None):
        import pdf
        self.temp_path = mkdtemp(prefix='pelicantests.')
        settings = {
            'PATH':
            os.path.join(os.path.dirname(CUR_DIR), '..', 'test_data',
                         'content'),
            'OUTPUT_PATH':
            self.temp_path,
            'PLUGINS': [pdf],
            'LOCALE':
            locale.normalize('en_US'),
        }
        if override:
            settings.update(override)

        self.settings = read_settings(override=settings)
        pelican = Pelican(settings=self.settings)

        try:
            pelican.run()
        except ValueError:
            logging.warn(
                'Relative links in the form of |filename|images/test.png are not yet handled by the pdf generator'
            )
            pass
def build_blog_from_git(main_dir, blog_dir):
    if os.path.isdir(blog_dir):
        shutil.rmtree(
            blog_dir
        )  # just fetch from the repo (including submodule dependencies)
    stdout, stderr = git.exec_command('clone',
                                      os.environ["URL_TO_GIT_REPO_HTTPS"],
                                      blog_dir,
                                      cwd=main_dir)
    _logger.info('Git stdout: {}, stderr: {}'.format(stdout.decode("utf-8"),
                                                     stderr.decode("utf-8")))
    os.chdir(blog_dir)

    stdout, stderr = git.exec_command(
        'clone',
        os.environ["URL_TO_GIT_REPO_THEME_HTTPS"],
        blog_dir + "/" + os.environ["THEME_NAME"],
        cwd=blog_dir)
    _logger.info('Git theme stdout: {}, stderr: {}'.format(
        stdout.decode("utf-8"), stderr.decode("utf-8")))

    settings = read_settings("publishconf.py")
    pelican = Pelican(settings)
    pelican.run()

    upload_recursively(blog_dir + "/output", os.environ["BUCKET_NAME"])
Example #17
0
    def test_generate_with_ipython2(self):
        '''Test generation of site with the plugin.'''

        base_path = os.path.dirname(os.path.abspath(__file__))
        base_path = os.path.join(base_path, 'test_data')
        content_path = os.path.join(base_path, 'content')
        output_path = os.path.join(base_path, 'output')
        settings_path = os.path.join(base_path, 'pelicanconf.py')
        settings = read_settings(path=settings_path,
                                 override={
                                     'PATH': content_path,
                                     'OUTPUT_PATH': self.temp_path,
                                     'CACHE_PATH': self.temp_cache,
                                 })

        pelican = Pelican(settings)
        pelican.run()

        # test existence
        assert os.path.exists(
            os.path.join(self.temp_path,
                         'test-ipython-notebook-nb-format-3.html'))
        assert os.path.exists(
            os.path.join(self.temp_path,
                         'test-ipython-notebook-nb-format-4.html'))
    def test_sites_generation(self):
        '''Test generation of sites with the plugin

        Compare with recorded output via ``git diff``.
        To generate output for comparison run the command
        ``pelican -o test_data/output -s test_data/pelicanconf.py \
        test_data/content``
        Remember to remove the output/ folder before that.
        '''
        base_path = os.path.dirname(os.path.abspath(__file__))
        base_path = os.path.join(base_path, 'test_data')
        content_path = os.path.join(base_path, 'content')
        output_path = os.path.join(base_path, 'output')
        settings_path = os.path.join(base_path, 'pelicanconf.py')
        settings = read_settings(path=settings_path, override={
            'PATH': content_path,
            'OUTPUT_PATH': self.temp_path,
            'CACHE_PATH': self.temp_cache,
            'PLUGINS': [i18ns],
            }
        )
        pelican = Pelican(settings)
        pelican.run()

        # compare output
        out, err = subprocess.Popen(
            ['git', 'diff', '--no-ext-diff', '--exit-code', '-w', output_path,
             self.temp_path], env={'PAGER': ''},
            stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()
        self.assertFalse(out, 'non-empty `diff` stdout:\n{}'.format(out))
        self.assertFalse(err, 'non-empty `diff` stderr:\n{}'.format(out))
class TestPelicanResume(unittest.TestCase):
    def setUp(self):
        self.temp_path = mkdtemp(prefix="pelican_resume.")
        self.settings = read_settings(path=None, override={
            "PATH": INPUT_PATH,
            "OUTPUT_PATH": self.temp_path,
            "PLUGINS": [pelican_resume],
            "FEED_ALL_ATOM": None,
            "CATEGORY_FEED_ATOM": None,
            "TRANSLATION_FEED_ATOM": None,
            "AUTHOR_FEED_ATOM": None,
            "AUTHOR_FEED_RSS": None,
        })
        self.pelican = Pelican(self.settings)
        self.pelican.run()

    def tearDown(self):
        rmtree(self.temp_path)

    def test_resume_exists(self):
        pdf = os.path.join(self.temp_path, "pdfs", "resume.pdf")
        self.assertTrue(os.path.exists(pdf))
        self.assertTrue(os.stat(pdf).st_size > 0)

    def test_moderncv(self):
        self.assertTrue(os.path.exists(os.path.join(pelican_resume.CSS_DIR, "moderncv.css")))
Example #20
0
 def test_custom_generation_works(self):
     # the same thing with a specified set of settings should work
     pelican = Pelican(path=INPUT_PATH,
                       output_path=self.temp_path,
                       settings=read_settings(SAMPLE_CONFIG))
     pelican.run()
     diff = dircmp(self.temp_path, os.sep.join((OUTPUT_PATH, "custom")))
     self.assertFilesEqual(diff)
Example #21
0
    def setUp(self, override=None):
        self.output_path = mkdtemp(prefix=TEST_DIR_PREFIX)
        self.content_path = mkdtemp(prefix=TEST_DIR_PREFIX)
        settings = {
            'PATH':
            self.content_path,
            'OUTPUT_PATH':
            self.output_path,
            'PLUGINS': [linkclass],
            'CACHE_CONTENT':
            False,
            'SITEURL':
            'http://example.org',
            'TIMEZONE':
            'UTC',
            'LINKCLASS': (('INTERNAL_CLASS', INTERNAL_CLASS, ''),
                          ('EXTERNAL_CLASS', EXTERNAL_CLASS, ''))
        }
        if override:
            settings.update(override)

        ## Generate the test Markdown source file
        fid = open(os.path.join(self.content_path, '%s.md' % TEST_FILE_STEM),
                   'w')
        fid.write('''Title: Test
Date: 1970-01-01

This is an [%s](%s), inline-style link.
This is an [%s](%s), inline-style link (with http URL).
This is an [%s](%s), inline-style link (with https URL).

This is an [%s][%s], reference-style link.
This is an [%s][%s], reference-style link (with http URL).
This is an [%s][%s], reference-style link (with https URL).

 [%s]: %s
 [%s]: %s
 [%s]: %s

''' % (INTERNAL_INLINE_TEXT, INTERNAL_INLINE_LINK, EXTERNAL_INLINE_TEXT_HTTP,
        EXTERNAL_INLINE_LINK_HTTP, EXTERNAL_INLINE_TEXT_HTTPS,
        EXTERNAL_INLINE_LINK_HTTP, INTERNAL_REFERENCE_TEXT,
        INTERNAL_REFERENCE_LABEL, EXTERNAL_REFERENCE_TEXT_HTTP,
        EXTERNAL_REFERENCE_LABEL_HTTP, EXTERNAL_REFERENCE_TEXT_HTTPS,
        EXTERNAL_REFERENCE_LABEL_HTTPS, INTERNAL_REFERENCE_LABEL,
        INTERNAL_REFERENCE_LINK, EXTERNAL_REFERENCE_LABEL_HTTP,
        EXTERNAL_REFERENCE_LINK_HTTP, EXTERNAL_REFERENCE_LABEL_HTTPS,
        EXTERNAL_REFERENCE_LINK_HTTPS))
        fid.close()

        ## Run the Pelican instance
        self.settings = read_settings(override=settings)
        pelican = Pelican(settings=self.settings)
        saved_stdout = sys.stdout
        sys.stdout = StringIO()
        pelican.run()
        sys.stdout = saved_stdout
Example #22
0
 def test_custom_generation_works(self):
     # the same thing with a specified set of settings should work
     with temporary_folder() as temp_path:
         pelican = Pelican(path=INPUT_PATH, output_path=temp_path,
                           settings=read_settings(SAMPLE_CONFIG))
         pelican.run()
         diff = dircmp(temp_path, os.sep.join((OUTPUT_PATH, "custom")))
         self.assertEqual(diff.left_only, [])
         self.assertEqual(diff.right_only, [])
         self.assertEqual(diff.diff_files, [])
Example #23
0
 def test_basic_generation_works(self):
     # when running pelican without settings, it should pick up the default
     # ones and generate correct output without raising any exception
     settings = read_settings(filename=None, override={
         'PATH': INPUT_PATH,
         'OUTPUT_PATH': self.temp_path,
         })
     pelican = Pelican(settings=settings)
     pelican.run()
     dcmp = dircmp(self.temp_path, os.sep.join((OUTPUT_PATH, "basic")))
     self.assertFilesEqual(recursiveDiff(dcmp))
Example #24
0
 def test_custom_generation_works(self):
     # the same thing with a specified set of settings should work
     settings = read_settings(path=SAMPLE_CONFIG, override={
         'PATH': INPUT_PATH,
         'OUTPUT_PATH': self.temp_path,
         'LOCALE': locale.normalize('en_US'),
         })
     pelican = Pelican(settings=settings)
     pelican.run()
     dcmp = dircmp(self.temp_path, os.sep.join((OUTPUT_PATH, "custom")))
     self.assertFilesEqual(recursiveDiff(dcmp))
Example #25
0
 def test_custom_generation_works(self):
     # the same thing with a specified set of settings should work
     settings = read_settings(filename=SAMPLE_CONFIG,
                              override={
                                  'PATH': INPUT_PATH,
                                  'OUTPUT_PATH': self.temp_path,
                              })
     pelican = Pelican(settings=settings)
     pelican.run()
     dcmp = dircmp(self.temp_path, os.sep.join((OUTPUT_PATH, "custom")))
     self.assertFilesEqual(recursiveDiff(dcmp))
Example #26
0
 def test_basic_generation_works(self):
     # when running pelican without settings, it should pick up the default
     # ones and generate the output without raising any exception / issuing
     # any warning.
     with temporary_folder() as temp_path:
         pelican = Pelican(path=INPUT_PATH, output_path=temp_path)
         pelican.run()
         diff = dircmp(temp_path, os.sep.join((OUTPUT_PATH, "basic")))
         self.assertEqual(diff.left_only, [])
         self.assertEqual(diff.right_only, [])
         self.assertEqual(diff.diff_files, [])
Example #27
0
 def test_basic_generation_works(self):
     # when running pelican without settings, it should pick up the default
     # ones and generate the output without raising any exception / issuing
     # any warning.
     with temporary_folder() as temp_path:
         pelican = Pelican(path=INPUT_PATH, output_path=temp_path)
         pelican.run()
         diff = dircmp(temp_path, os.sep.join((OUTPUT_PATH, "basic")))
         self.assertEqual(diff.left_only, [])
         self.assertEqual(diff.right_only, [])
         self.assertEqual(diff.diff_files, [])
Example #28
0
 def test_basic_generation_works(self):
     # when running pelican without settings, it should pick up the default
     # ones and generate the output without raising any exception / issuing
     # any warning.
     with patch("pelican.contents.getenv") as mock_getenv:
         # force getenv('USER') to always return the same value
         mock_getenv.return_value = "Dummy Author"
         pelican = Pelican(path=INPUT_PATH, output_path=self.temp_path)
         pelican.run()
         diff = dircmp(self.temp_path, os.sep.join((OUTPUT_PATH, "basic")))
         self.assertFilesEqual(diff)
Example #29
0
 def test_custom_generation_works(self):
     # the same thing with a specified set of settings should work
     with temporary_folder() as temp_path:
         pelican = Pelican(path=INPUT_PATH,
                           output_path=temp_path,
                           settings=read_settings(SAMPLE_CONFIG))
         pelican.run()
         diff = dircmp(temp_path, os.sep.join((OUTPUT_PATH, "custom")))
         self.assertEqual(diff.left_only, [])
         self.assertEqual(diff.right_only, [])
         self.assertEqual(diff.diff_files, [])
Example #30
0
 def test_if_DELETE_OUTPUT_DIRECTORY_is_true_then_raise(self):
     """
         WHEN DELETE_OUTPUT_DIRECTORY is True
         THEN we'll raise an exception
     """
     settings = read_settings(path=None,
                              override={
                                  'DELETE_OUTPUT_DIRECTORY': True,
                                  'PLUGINS': [pelican_ab]})
     pelican = Pelican(settings)
     with self.assertRaises(RuntimeError):
         pelican.run()
Example #31
0
def pelican_generate(files_path):
    content_path = os.path.join(files_path, 'content')
    conf_path = os.path.join(files_path, 'pelicanconf.py')
    output_path = os.path.join(files_path, 'output')
    settings = read_settings(conf_path)
    pelican = Pelican(
        settings=settings,
        path=content_path,
        output_path=output_path,
        theme='notmyidea'
    )
    pelican.run()
Example #32
0
    def test_order_of_generators(self):
        # StaticGenerator must run last, so it can identify files that
        # were skipped by the other generators, and so static files can
        # have their output paths overridden by the {attach} link syntax.

        pelican = Pelican(settings=read_settings(path=None))
        generator_classes = pelican.get_generator_classes()

        self.assertTrue(generator_classes[-1] is StaticGenerator,
            "StaticGenerator must be the last generator, but it isn't!")
        self.assertIsInstance(generator_classes, collections.Sequence,
            "get_generator_classes() must return a Sequence to preserve order")
Example #33
0
 def test_custom_generation_works(self):
     # the same thing with a specified set of settings should work
     settings = read_settings(path=SAMPLE_CONFIG,
                              override={
                                  'PATH': INPUT_PATH,
                                  'OUTPUT_PATH': self.temp_path,
                                  'LOCALE': locale.normalize('en_US'),
                              })
     pelican = Pelican(settings=settings)
     pelican.run()
     dcmp = dircmp(self.temp_path, os.path.join(OUTPUT_PATH, 'custom'))
     self.assertFilesEqual(recursiveDiff(dcmp))
Example #34
0
 def test_basic_generation_works(self):
     # when running pelican without settings, it should pick up the default
     # ones and generate correct output without raising any exception
     settings = read_settings(filename=None,
                              override={
                                  'PATH': INPUT_PATH,
                                  'OUTPUT_PATH': self.temp_path,
                              })
     pelican = Pelican(settings=settings)
     pelican.run()
     dcmp = dircmp(self.temp_path, os.sep.join((OUTPUT_PATH, "basic")))
     self.assertFilesEqual(recursiveDiff(dcmp))
Example #35
0
    def test_basic_generation_works(self):
        # when running pelican without settings, it should pick up the default
        # ones and generate the output without raising any exception / issuing
        # any warning.
        with temporary_folder() as temp_path:
            pelican = Pelican(path=INPUT_PATH, output_path=temp_path)
            pelican.run()

        # the same thing with a specified set of settins should work
        with temporary_folder() as temp_path:
            pelican = Pelican(path=INPUT_PATH, output_path=temp_path,
                              settings=read_settings(SAMPLE_CONFIG))
Example #36
0
 def test_basic_generation_works(self):
     # when running pelican without settings, it should pick up the default
     # ones and generate the output without raising any exception / issuing
     # any warning.
     with patch("pelican.contents.getenv") as mock_getenv:
         # force getenv('USER') to always return the same value
         mock_getenv.return_value = "Dummy Author"
         pelican = Pelican(path=INPUT_PATH, output_path=self.temp_path)
         pelican.run()
         diff = dircmp(
                 self.temp_path, os.sep.join((OUTPUT_PATH, "basic")))
         self.assertFilesEqual(diff)
Example #37
0
def call_pelican(settings_path, content_path):
    settings_path = os.path.abspath(settings_path)
    content_path = os.path.abspath(content_path)

    settings = read_settings(settings_path)
    settings_dir = os.path.split(settings_path)[0]
    curdir = os.getcwd()
    os.chdir(settings_dir)
    settings["THEME"] = os.path.abspath(settings["THEME"])
    os.chdir(curdir)
    p = Pelican(settings=settings)
    p.run()
Example #38
0
 def setUp(self):
     self.temp_path = mkdtemp(prefix='pelicanfly.')
     pelicanfly_path, _ = os.path.join(os.path.split(pelicanfly.__file__))
     self.pelicanfly_static = os.path.join(pelicanfly_path, 'static')
     self.settings = read_settings(path=None,
                                   override={
                                       'PATH': INPUT_PATH,
                                       'OUTPUT_PATH': self.temp_path,
                                       'PLUGINS': [pelicanfly]
                                   })
     self.pelican = Pelican(self.settings)
     self.pelican.run()
     pass
Example #39
0
 def test_basic_generation_works(self):
     # when running pelican without settings, it should pick up the default
     # ones and generate correct output without raising any exception
     settings = read_settings(filename=None, override={"PATH": INPUT_PATH, "OUTPUT_PATH": self.temp_path})
     pelican = Pelican(settings=settings)
     pelican.run()
     dcmp = dircmp(self.temp_path, os.sep.join((OUTPUT_PATH, "basic")))
     self.assertFilesEqual(recursiveDiff(dcmp))
     self.assertEqual(
         self.logcount_handler.count_logs(msg="Unable to find.*skipping url replacement", level=logging.WARNING),
         10,
         msg="bad number of occurences found for this log",
     )
Example #40
0
    def setUp(self, override=None):
        self.temp_path = mkdtemp()
        settings = {
            'PATH': os.path.join(CUR_DIR, 'content', 'TestCategory'),
            'OUTPUT_PATH': self.temp_path,
            'PLUGINS': ['pelican.plugins.assets', ],
            'THEME': THEME_DIR,
        }
        if override:
            settings.update(override)

        self.settings = read_settings(override=settings)
        pelican = Pelican(settings=self.settings)
        pelican.run()
Example #41
0
    def setUp(self, override=None):
        self.temp_path = mkdtemp()
        settings = {
            'PATH': os.path.join(CUR_DIR, 'content', 'TestCategory'),
            'OUTPUT_PATH': self.temp_path,
            'PLUGINS': ['pelican.plugins.assets', ],
            'THEME': THEME_DIR,
        }
        if override:
            settings.update(override)

        self.settings = read_settings(override=settings)
        pelican = Pelican(settings=self.settings)
        pelican.run()
    def setUp (self, override = None):
        self.output_path = mkdtemp (prefix = TEST_DIR_PREFIX)
        self.content_path = mkdtemp (prefix = TEST_DIR_PREFIX)
        settings = {
            'PATH': self.content_path,
            'OUTPUT_PATH': self.output_path,
            'PLUGINS': [linkclass],
            'CACKHE_CONTENT': False,
            'LINKCLASS_INTERNAL_CLASS': INTERNAL_CLASS,
            'LINKCLASS_EXTERNAL_CLASS': EXTERNAL_CLASS
        }
        if override:
            settings.update (override)

        ## Generate the test Markdown source file
        fid = open (os.path.join (self.content_path, '%s.md' % TEST_FILE_STEM),
                    'w')
        fid.write ('''Title: Test
Date: 1970-01-01

This is an [%s](%s), inline-style link.
This is an [%s](%s), inline-style link (with http URL).
This is an [%s](%s), inline-style link (with https URL).

This is an [%s][%s], reference-style link.
This is an [%s][%s], reference-style link (with http URL).
This is an [%s][%s], reference-style link (with https URL).

 [%s]: %s
 [%s]: %s
 [%s]: %s

''' % (INTERNAL_INLINE_TEXT, INTERNAL_INLINE_LINK,
       EXTERNAL_INLINE_TEXT_HTTP, EXTERNAL_INLINE_LINK_HTTP,
       EXTERNAL_INLINE_TEXT_HTTPS, EXTERNAL_INLINE_LINK_HTTP,
       INTERNAL_REFERENCE_TEXT, INTERNAL_REFERENCE_LABEL,
       EXTERNAL_REFERENCE_TEXT_HTTP, EXTERNAL_REFERENCE_LABEL_HTTP,
       EXTERNAL_REFERENCE_TEXT_HTTPS, EXTERNAL_REFERENCE_LABEL_HTTPS,
       INTERNAL_REFERENCE_LABEL, INTERNAL_REFERENCE_LINK,
       EXTERNAL_REFERENCE_LABEL_HTTP, EXTERNAL_REFERENCE_LINK_HTTP,
       EXTERNAL_REFERENCE_LABEL_HTTPS, EXTERNAL_REFERENCE_LINK_HTTPS))
        fid.close ()

        ## Run the Pelican instance
        self.settings = read_settings (override = settings)
        pelican = Pelican (settings = self.settings)
        saved_stdout = sys.stdout
        sys.stdout = StringIO ()
        pelican.run ()
        sys.stdout = saved_stdout
Example #43
0
    def test_order_of_generators(self):
        # StaticGenerator must run last, so it can identify files that
        # were skipped by the other generators, and so static files can
        # have their output paths overridden by the {attach} link syntax.

        pelican = Pelican(settings=read_settings(path=None))
        generator_classes = pelican.get_generator_classes()

        self.assertTrue(
            generator_classes[-1] is StaticGenerator,
            "StaticGenerator must be the last generator, but it isn't!")
        self.assertIsInstance(
            generator_classes, collections.Sequence,
            "get_generator_classes() must return a Sequence to preserve order")
Example #44
0
 def test_basic_generation_works(self):
     # when running pelican without settings, it should pick up the default
     # ones and generate the output without raising any exception / issuing
     # any warning.
     with patch("pelican.contents.getenv") as mock_getenv:
         # force getenv('USER') to always return the same value
         mock_getenv.return_value = "Dummy Author"
         settings = read_settings(filename=None, override={
             'PATH': INPUT_PATH,
             'OUTPUT_PATH': self.temp_path,
             })
         pelican = Pelican(settings=settings)
         pelican.run()
         dcmp = dircmp(self.temp_path, os.sep.join((OUTPUT_PATH, "basic")))
         self.assertFilesEqual(recursiveDiff(dcmp))
 def test_ok_on_custom_data(self):
     settings = get_settings(filenames={})
     settings["PATH"] = join(CUR_DIR, "test_data")
     settings["PLUGINS"] = ["pelican-ipynb.markup"]  # to also parse .ipynb files
     configure_settings(settings)
     pelican_mock = PelicanMock(settings)
     pelican_init(pelican_mock)
     Pelican.init_plugins(pelican_mock)
     with TemporaryDirectory() as tmpdirname:
         generator = _build_article_generator(settings, tmpdirname)
         process_rst_and_summaries([generator])
         for article in generator.articles:
             if article.source_path.endswith(".rst"):
                 self.assertIn("mathjaxscript_pelican", article.content)
         generator.generate_output(Writer(tmpdirname, settings=settings))
Example #46
0
    def setUp(self, override=None):
        self.temp_path = mkdtemp(prefix="pelicantests.")
        settings = {
            "PATH": os.path.join(CUR_DIR, "test_data"),
            "OUTPUT_PATH": self.temp_path,
            "PLUGINS": [pdf],
            "LOCALE": locale.normalize("en_US"),
        }
        if override:
            settings.update(override)

        self.settings = read_settings(override=settings)
        pelican = Pelican(settings=self.settings)

        pelican.run()
Example #47
0
 def setUp(self):
     self.temp_path = mkdtemp(prefix="pelicanfly.")
     pelicanfly_path, _ = os.path.join(os.path.split(pelicanfly.__file__))
     self.pelicanfly_static = os.path.join(pelicanfly_path, "static")
     self.settings = read_settings(
         path=None,
         override={
             "PATH": INPUT_PATH,
             "OUTPUT_PATH": self.temp_path,
             "PLUGINS": [pelicanfly],
         },
     )
     self.pelican = Pelican(self.settings)
     self.pelican.run()
     pass
Example #48
0
 def test_cyclic_intersite_links_no_warnings(self):
     settings = read_settings(path=None,
                              override={
                                  'PATH':
                                  os.path.join(CURRENT_DIR,
                                               'cyclic_intersite_links'),
                                  'OUTPUT_PATH':
                                  self.temp_path,
                                  'CACHE_PATH':
                                  self.temp_cache,
                              })
     pelican = Pelican(settings=settings)
     mute(True)(pelican.run)()
     # There are four different intersite links:
     # - one pointing to the second article from first and third
     # - one pointing to the first article from second and third
     # - one pointing to the third article from first and second
     # - one pointing to a nonexistent from each
     # If everything goes well, only the warning about the nonexistent
     # article should be printed. Only two articles are not sufficient,
     # since the first will always have _context['generated_content'] empty
     # (thus skipping the link resolving) and the second will always have it
     # non-empty, containing the first, thus always succeeding.
     self.assertLogCountEqual(
         count=1,
         msg="Unable to find '.*\\.rst', skipping url replacement.",
         level=logging.WARNING)
Example #49
0
 def test_write_only_selected(self):
     """Test that only the selected files are written"""
     settings = read_settings(path=None,
                              override={
                                  'PATH':
                                  INPUT_PATH,
                                  'OUTPUT_PATH':
                                  self.temp_path,
                                  'CACHE_PATH':
                                  self.temp_cache,
                                  'WRITE_SELECTED': [
                                      os.path.join(self.temp_path,
                                                   'oh-yeah.html'),
                                      os.path.join(self.temp_path,
                                                   'categories.html'),
                                  ],
                                  'LOCALE':
                                  locale.normalize('en_US'),
                              })
     pelican = Pelican(settings=settings)
     logger = logging.getLogger()
     orig_level = logger.getEffectiveLevel()
     logger.setLevel(logging.INFO)
     mute(True)(pelican.run)()
     logger.setLevel(orig_level)
     self.assertLogCountEqual(count=2, msg="Writing .*", level=logging.INFO)
Example #50
0
    def test_theme_static_paths_copy(self):
        # the same thing with a specified set of settings should work
        settings = read_settings(path=SAMPLE_CONFIG,
                                 override={
                                     'PATH':
                                     INPUT_PATH,
                                     'OUTPUT_PATH':
                                     self.temp_path,
                                     'CACHE_PATH':
                                     self.temp_cache,
                                     'THEME_STATIC_PATHS': [
                                         os.path.join(SAMPLES_PATH, 'very'),
                                         os.path.join(SAMPLES_PATH, 'kinda'),
                                         os.path.join(SAMPLES_PATH,
                                                      'theme_standard')
                                     ]
                                 })
        pelican = Pelican(settings=settings)
        mute(True)(pelican.run)()
        theme_output = os.path.join(self.temp_path, 'theme')
        extra_path = os.path.join(theme_output, 'exciting', 'new', 'files')

        for file in ['a_stylesheet', 'a_template']:
            self.assertTrue(os.path.exists(os.path.join(theme_output, file)))

        for file in ['wow!', 'boom!', 'bap!', 'zap!']:
            self.assertTrue(os.path.exists(os.path.join(extra_path, file)))
Example #51
0
 def test_basic_generation_works(self):
     # when running pelican without settings, it should pick up the default
     # ones and generate correct output without raising any exception
     settings = read_settings(path=None, override={
         'PATH': INPUT_PATH,
         'OUTPUT_PATH': self.temp_path,
         'LOCALE': locale.normalize('en_US'),
         })
     pelican = Pelican(settings=settings)
     pelican.run()
     dcmp = dircmp(self.temp_path, os.sep.join((OUTPUT_PATH, "basic")))
     self.assertFilesEqual(recursiveDiff(dcmp))
     self.assertLogCountEqual(
         count=10,
         msg="Unable to find.*skipping url replacement",
         level=logging.WARNING)
Example #52
0
    def setUp(self, override=None):
        import assets
        self.temp_path = mkdtemp(prefix='pelicantests.')
        settings = {
            'PATH': os.path.join(os.path.dirname(CUR_DIR), 'test_data', 'content'),
            'OUTPUT_PATH': self.temp_path,
            'PLUGINS': [assets],
            'THEME': THEME_DIR,
            'LOCALE': locale.normalize('en_US'),
        }
        if override:
            settings.update(override)

        self.settings = read_settings(override=settings)
        pelican = Pelican(settings=self.settings)
        pelican.run()
Example #53
0
 def test_basic_generation_works(self):
     # when running pelican without settings, it should pick up the default
     # ones and generate the output without raising any exception / issuing
     # any warning.
     with patch("pelican.contents.getenv") as mock_getenv:
         # force getenv('USER') to always return the same value
         mock_getenv.return_value = "Dummy Author"
         settings = read_settings(filename=None,
                                  override={
                                      'PATH': INPUT_PATH,
                                      'OUTPUT_PATH': self.temp_path,
                                  })
         pelican = Pelican(settings=settings)
         pelican.run()
         dcmp = dircmp(self.temp_path, os.sep.join((OUTPUT_PATH, "basic")))
         self.assertFilesEqual(recursiveDiff(dcmp))
    def setUp (self, encoding = None, base_path = None):

        self.output_path = mkdtemp (prefix = TEST_DIR_PREFIX)
        self.content_path = mkdtemp (prefix = TEST_DIR_PREFIX)

        settings = {
            'PATH': self.content_path,
            'OUTPUT_PATH': self.output_path,
            'PLUGINS': [md_include],
            'CACHE_CONTENT': False
        }

        if base_path:
            include_dir = os.path.join (self.content_path, base_path)
            os.makedirs (include_dir)
        else:
            include_dir = self.content_path
        settings ['MD_INCLUDE_BASE_PATH'] = include_dir

        if encoding:
            settings ['MD_INCLUDE_ENCODING'] = encoding

        ## Create the article file
        fid = open (os.path.join (self.content_path, '%s.md' % TEST_FILE_STEM),
                    'w')
        fid.write ('''Title: Test
Date:

{!%s!}
''' % INCLUDE_FILENAME)
        fid.close ()

        ## Create the included file
        if encoding:
            encoded_content = INCLUDED_CONTENT.decode ('utf-8').encode (encoding)
        else:
            encoded_content = INCLUDED_CONTENT
        fid = open (os.path.join (include_dir, INCLUDE_FILENAME), 'w')
        fid.write (encoded_content)
        fid.write ('\n')
        fid.close ()

        ## Run the Pelican instance
        self.settings = read_settings (override = settings)
        pelican = Pelican (settings = self.settings)
        pelican.run ()
 def testKnitrSettings(self):
     settings = read_settings(path=None, override={
         'PATH': self.contentdir,
         'OUTPUT_PATH': self.outputdir,
         'KNITR_OPTS_CHUNK': {'fig.path' : '%s/' % self.figpath},
         'PLUGIN_PATHS': ['../'],
         'PLUGINS': ['rmd_reader'],
     })
     pelican = Pelican(settings=settings)
     pelican.run()
     
     outputfilename = os.path.join(self.outputdir,'%s.html' % self.testtitle)
     self.assertTrue(os.path.exists(outputfilename),'File %s was not created.' % outputfilename)
     imagesdir = os.path.join(self.outputdir,self.figpath)
     self.assertTrue(os.path.exists(imagesdir), 'figpath not created.')
     images = glob.glob('%s/*' % imagesdir)
     self.assertTrue(len(images) == 1,'Contents of images dir is not correct: %s' % ','.join(images))
    def __execute_pelican(self, settings_override=None):
        """
        Executes pelican. Uses the minimal config of self.settings_default (that will fail!) merged with the given additional settings.
        :param settings_override: dictionary with pelican setting values to set
        :type settings_override: dict
        """
        if not settings_override:
            settings_override = {}

        settings = self.settings_default.copy()
        settings.update(settings_override)

        pelican_settings = read_settings(
            path=None,
            override=settings
        )
        pelican = Pelican(settings=pelican_settings)
        pelican.run()
Example #57
0
def mkpelican():
    """runs pelican build"""

    def fullthemepath(tpath):
        """joins theme path"""
        return path.join(PELIC_PATH, tpath)

    psettings = get_settings_from_file(PELIC_CONFIG)
    psettings["PATH"] = PELIC_CONTENT
    psettings["OUTPUT_PATH"] = PELIC_OUTPUT
    psettings["THEME"] = fullthemepath(psettings["THEME"])

    message(
        "running something similar to 'pelican -t %s -s %s %s -o %s'"
        % (psettings["THEME"], PELIC_CONFIG, PELIC_CONTENT, PELIC_OUTPUT),
        shout=True,
    )
    pinst = Pelican(configure_settings(psettings))
    pinst.run()
Example #58
0
 def test_basic_generation_works(self):
     # when running pelican without settings, it should pick up the default
     # ones and generate the output without raising any exception / issuing
     # any warning.
     with patch("pelican.contents.getenv") as mock_getenv:
         # force getenv('USER') to always return the same value
         mock_getenv.return_value = "Dummy Author"
         pelican = Pelican(path=INPUT_PATH, output_path=self.temp_path)
         pelican.run()
         diff = dircmp(self.temp_path, os.sep.join((OUTPUT_PATH, "basic")))
         self.assertEqual(
             diff.left_only,
             [],
             msg="some generated "
             "files are absent from the expected functional "
             "tests output.\n"
             "This is probably because the HTML generated files "
             "changed. If these changes are normal, please refer "
             "to docs/contribute.rst to update the expected "
             "output of the functional tests.",
         )
         self.assertEqual(
             diff.right_only,
             [],
             msg="some files from "
             "the expected functional tests output are absent "
             "from the current output.\n"
             "This is probably because the HTML generated files "
             "changed. If these changes are normal, please refer "
             "to docs/contribute.rst to update the expected "
             "output of the functional tests.",
         )
         self.assertEqual(
             diff.diff_files,
             [],
             msg="some generated "
             "files differ from the expected functional tests "
             "output.\n"
             "This is probably because the HTML generated files "
             "changed. If these changes are normal, please refer "
             "to docs/contribute.rst to update the expected "
             "output of the functional tests.",
         )
Example #59
0
File: api.py Project: dn0/mailpy
    def __init__(self, settings_file, repo_path=None, images_dir='images', files_dir='files'):
        if repo_path is True:
            repo_path = os.path.abspath(os.path.dirname(settings_file))

        self.repo_path = repo_path
        self.images_dir = images_dir
        self.files_dir = files_dir
        self.settings = read_settings(settings_file)
        self.pelican = Pelican(self.settings)
        self.article_extensions = tuple([ext for cls in self.article_classes for ext in cls.file_extensions])