Ejemplo n.º 1
0
def test_simple_render(tmpdir):
    foo_page = '# hello\n\nthis is a test foo: {{ foo }}'
    mktree(
        tmpdir, {
            'pages': {
                'foobar.md': foo_page,
                'spam.html': '# SPAM',
                'favicon.ico': '*',
            },
            'theme/templates/main.jinja': 'main, content:\n\n{{ content }}',
            'tmp/content/foobar.md': foo_page,
        })
    config = Config(
        source_dir=str(tmpdir),
        tmp_dir=str(tmpdir.join('tmp')),
        foo='bar',
    )

    som = {
        'pages': {
            'foobar.md': {
                'uri': '/foobar.html',
                'infile': config.pages_dir / 'foobar.md',
                'template': 'main.jinja',
                'content_template': Path('content') / 'foobar.md',
            },
            'favicon.ico': {
                'uri': '/favicon.ico',
                'infile': config.pages_dir / 'favicon.ico',
            },
        }
    }
    expected_tree = {
        'foobar.html': ('main, content:\n\n'
                        '<h1 id="1-hello">hello</h1>\n\n'
                        '<p>this is a test foo: </p>\n'),
        'favicon.ico':
        '*',
    }
    assert not tmpdir.join('dist').check()

    assert render_pages(config, som) is None
    assert gettree(tmpdir.join('dist')) == expected_tree

    tmpdir.join('dist').remove(rec=1)
    assert not tmpdir.join('dist').check()

    cache = render_pages(config, som, {})
    assert gettree(tmpdir.join('dist')) == expected_tree
    assert len(cache) == 2

    tmpdir.join('dist').remove(rec=1)
    assert not tmpdir.join('dist').check()

    render_pages(config, som, cache)
    assert gettree(tmpdir.join('dist')) != expected_tree
Ejemplo n.º 2
0
def test_build_simple_som(tmpdir):
    mktree(
        tmpdir, {
            'dist/theme/assets/whatever.1234567.png': '**',
            'pages': {
                'foobar.md': '# hello\n\nthis is a test foo: {{ foo }}',
                'posts/2032-06-01-testing.html': '# testing',
                'static/image.png': '*',
            },
            'theme/templates/main.jinja': 'main, content:\n\n {{ content }}',
        })
    config = Config(source_dir=str(tmpdir),
                    tmp_dir=str(tmpdir.join('tmp')),
                    foo='bar',
                    defaults={'/posts/*': {
                        'uri': '/foobar/{slug}.html'
                    }})

    pages = build_pages(config)
    content_templates(pages.values(), config)
    source_dir = Path(tmpdir)
    # debug(som)
    assert {
        '/foobar.md': {
            'infile': source_dir / 'pages/foobar.md',
            'content_template': 'content/foobar.md',
            'title': 'Foobar',
            'slug': 'foobar',
            'created': CloseToNow(),
            'uri': '/foobar/',
            'template': None,
            'content': ('# hello\n'
                        '\n'
                        'this is a test foo: {{ foo }}'),
            'pass_through': False,
        },
        '/posts/2032-06-01-testing.html': {
            'infile': source_dir / 'pages/posts/2032-06-01-testing.html',
            'content_template': 'content/posts/2032-06-01-testing.html',
            'title': 'Testing',
            'slug': 'testing',
            'created': datetime(2032, 6, 1, 0, 0),
            'uri': '/foobar/testing.html',
            'template': None,
            'content': '# testing',
            'pass_through': False,
        },
        '/static/image.png': {
            'infile': source_dir / 'pages/static/image.png',
            'title': 'image.png',
            'slug': 'image.png',
            'created': CloseToNow(),
            'uri': '/static/image.png',
            'pass_through': True,
        }
    } == pages
Ejemplo n.º 3
0
def test_harrier_watcher(tmpdir):
    mktree(tmpdir, {
        'pages/foobar.md': '# hello',
        'theme/templates/main.jinja': 'main:\n {{ content }}',
    })
    harrier.dev.CONFIG = Config(source_dir=tmpdir)
    watcher = HarrierWatcher(Path(tmpdir))
    assert not watcher.should_watch_dir(Entry(tmpdir.join('foobar')))
    assert not watcher.should_watch_dir(Entry(tmpdir.join('__pycache__')))
    assert watcher.should_watch_dir(Entry(tmpdir.join('pages')))
    assert watcher.should_watch_dir(Entry(tmpdir.join('pages/whatever')))
    harrier.dev.CONFIG = None
Ejemplo n.º 4
0
def test_placeholders_error(tmpdir):
    mktree(tmpdir, {
        'pages': {
            'posts/2032-06-01-testing.html': '# testing',
        },
    })
    config = Config(
        source_dir=str(tmpdir),
        tmp_dir=str(tmpdir.join('tmp')),
        foo='bar',
        defaults={'/posts/*': {
            'testing': '{{ title }}-{{ foobar }}',
        }})

    with pytest.raises(HarrierProblem):
        build_pages(config)
Ejemplo n.º 5
0
def test_build_default_placeholders(tmpdir):
    mktree(tmpdir, {
        'pages': {
            'posts/2032-06-01-testing.html': '# testing',
        },
    })
    config = Config(source_dir=str(tmpdir),
                    tmp_dir=str(tmpdir.join('tmp')),
                    foo='bar',
                    defaults={
                        '/posts/*': {
                            'uri':
                            '/foobar/{slug}.html',
                            'test_attr':
                            'Brain J',
                            'str_attr':
                            '{{ title }}-{{ test_attr }}',
                            'dict_attrs': {
                                'd_attr': '{{ test_attr }}',
                                'd_foo': 'foo',
                            },
                            'list_attrs': ['foo', 'bar', '{{ title }}'],
                            'list_of_dicts_attr': [{
                                'a_key': '{{ title }}-{{ test_attr }}',
                                'b_key': 'foo bar',
                            }]
                        }
                    })

    pages = build_pages(config)
    content_templates(pages.values(), config)
    source_dir = Path(tmpdir)
    assert {
        '/posts/2032-06-01-testing.html': {
            'infile':
            source_dir / 'pages/posts/2032-06-01-testing.html',
            'content_template':
            'content/posts/2032-06-01-testing.html',
            'title':
            'Testing',
            'slug':
            'testing',
            'created':
            datetime(2032, 6, 1, 0, 0),
            'uri':
            '/foobar/testing.html',
            'str_attr':
            'Testing-Brain J',
            'test_attr':
            'Brain J',
            'dict_attrs': {
                'd_attr': 'Brain J',
                'd_foo': 'foo'
            },
            'list_attrs': ['foo', 'bar', 'Testing'],
            'list_of_dicts_attr': [{
                'a_key': 'Testing-Brain J',
                'b_key': 'foo bar',
            }],
            'template':
            None,
            'content':
            '# testing',
            'pass_through':
            False,
        },
    } == pages