How to use Publ - 10 common examples

To help you get started, we’ve selected a few Publ examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github PlaidWeb / Publ / tests / test_utils.py View on Github external
""" test of utils.make_tag """

    assert utils.make_tag('a', {'href': 'foo'}, False) == '<a href="foo">'
    assert utils.make_tag('a',
                          [('href', 'foo'), ('href', 'bar')],
                          True) == '</a><a href="foo">'
    with pytest.raises(Exception):
        utils.make_tag('a', (('href', 'foo')))

    app = flask.Flask(__name__)
    with app.test_request_context():
        proxy = utils.CallableValue("")
        assert utils.make_tag('a', {'href': proxy}) == '</a><a href="<hello>">'

    escaped = flask.Markup("&amp;")
    assert utils.make_tag('a', {'href': escaped}) == '</a><a href="&amp;">'
</a>
github PlaidWeb / Publ / tests / test_utils.py View on Github external
def test_make_tag():
    """ test of utils.make_tag """

    assert utils.make_tag('a', {'href': 'foo'}, False) == '<a href="foo">'
    assert utils.make_tag('a',
                          [('href', 'foo'), ('href', 'bar')],
                          True) == '</a><a href="foo">'
    with pytest.raises(Exception):
        utils.make_tag('a', (('href', 'foo')))

    app = flask.Flask(__name__)
    with app.test_request_context():
        proxy = utils.CallableValue("")
        assert utils.make_tag('a', {'href': proxy}) == '</a><a href="<hello>">'

    escaped = flask.Markup("&amp;")
    assert utils.make_tag('a', {'href': escaped}) == '</a><a href="&amp;">'
</a>
github PlaidWeb / Publ / tests / test_utils.py View on Github external
""" test functions involving the ListLike inference class """
    assert utils.is_list((1, 2, 3))
    assert utils.is_list([])
    assert utils.is_list([1, 2, 3])
    assert utils.is_list({1, 2, 3})
    assert utils.is_list(frozenset((1, 2, 3)))
    assert utils.is_list(utils.TagSet(('1', '2', 'A', 'a')))
    assert not utils.is_list("")
    assert not utils.is_list("foo")
    assert not utils.is_list(123)
    assert not utils.is_list(True)
    assert not utils.is_list(None)

    assert utils.as_list([1, 2, 3]) == [1, 2, 3]
    assert utils.as_list((1, 2, 3)) == (1, 2, 3)
    assert utils.as_list("foo") == ("foo",)
    assert utils.as_list(True) == (True,)
    assert utils.as_list(None) == ()
github PlaidWeb / Publ / tests / test_utils.py View on Github external
assert utils.is_list([])
    assert utils.is_list([1, 2, 3])
    assert utils.is_list({1, 2, 3})
    assert utils.is_list(frozenset((1, 2, 3)))
    assert utils.is_list(utils.TagSet(('1', '2', 'A', 'a')))
    assert not utils.is_list("")
    assert not utils.is_list("foo")
    assert not utils.is_list(123)
    assert not utils.is_list(True)
    assert not utils.is_list(None)

    assert utils.as_list([1, 2, 3]) == [1, 2, 3]
    assert utils.as_list((1, 2, 3)) == (1, 2, 3)
    assert utils.as_list("foo") == ("foo",)
    assert utils.as_list(True) == (True,)
    assert utils.as_list(None) == ()
github PlaidWeb / Publ / tests / test_utils.py View on Github external
def test_static_url():
    """ tests for the static URL builder """
    app = flask.Flask("tests", static_folder="asdf")
    with app.test_request_context("https://foo.bar/poiupoiupoiu"):
        assert utils.static_url("thing", absolute=False) == "/asdf/thing"
        assert utils.static_url("thong", absolute=True) == "https://foo.bar/asdf/thong"
github PlaidWeb / Publ / tests / test_utils.py View on Github external
tzinfo=app.publ_config.timezone)

        with pytest.raises(ValueError):
            utils.parse_date("not a date")
        with pytest.raises(ValueError):
            utils.parse_date("12345678")
        with pytest.raises(ValueError):
            utils.parse_date("")

        assert utils.parse_date('1978-06-14') == (make_date(1978, 6, 14), 'day', utils.DAY_FORMAT)
        assert utils.parse_date('19780614') == (make_date(1978, 6, 14), 'day', utils.DAY_FORMAT)

        assert utils.parse_date('1983-07') == (make_date(1983, 7), 'month', utils.MONTH_FORMAT)
        assert utils.parse_date('198307') == (make_date(1983, 7), 'month', utils.MONTH_FORMAT)

        assert utils.parse_date("1979") == (make_date(1979), 'year', utils.YEAR_FORMAT)

        assert utils.parse_date('19810505_w') == (make_date(1981, 5, 4), 'week', utils.WEEK_FORMAT)
github PlaidWeb / Publ / tests / test_utils.py View on Github external
with pytest.raises(ValueError):
            utils.parse_date("not a date")
        with pytest.raises(ValueError):
            utils.parse_date("12345678")
        with pytest.raises(ValueError):
            utils.parse_date("")

        assert utils.parse_date('1978-06-14') == (make_date(1978, 6, 14), 'day', utils.DAY_FORMAT)
        assert utils.parse_date('19780614') == (make_date(1978, 6, 14), 'day', utils.DAY_FORMAT)

        assert utils.parse_date('1983-07') == (make_date(1983, 7), 'month', utils.MONTH_FORMAT)
        assert utils.parse_date('198307') == (make_date(1983, 7), 'month', utils.MONTH_FORMAT)

        assert utils.parse_date("1979") == (make_date(1979), 'year', utils.YEAR_FORMAT)

        assert utils.parse_date('19810505_w') == (make_date(1981, 5, 4), 'week', utils.WEEK_FORMAT)
github PlaidWeb / Publ / tests / test_utils.py View on Github external
with app.app_context():
        def make_date(year=None, month=None, day=None):
            return arrow.Arrow(year=year or 1,
                               month=month or 1,
                               day=day or 1,
                               tzinfo=app.publ_config.timezone)

        with pytest.raises(ValueError):
            utils.parse_date("not a date")
        with pytest.raises(ValueError):
            utils.parse_date("12345678")
        with pytest.raises(ValueError):
            utils.parse_date("")

        assert utils.parse_date('1978-06-14') == (make_date(1978, 6, 14), 'day', utils.DAY_FORMAT)
        assert utils.parse_date('19780614') == (make_date(1978, 6, 14), 'day', utils.DAY_FORMAT)

        assert utils.parse_date('1983-07') == (make_date(1983, 7), 'month', utils.MONTH_FORMAT)
        assert utils.parse_date('198307') == (make_date(1983, 7), 'month', utils.MONTH_FORMAT)

        assert utils.parse_date("1979") == (make_date(1979), 'year', utils.YEAR_FORMAT)

        assert utils.parse_date('19810505_w') == (make_date(1981, 5, 4), 'week', utils.WEEK_FORMAT)
github PlaidWeb / Publ / tests / test_utils.py View on Github external
month=month or 1,
                               day=day or 1,
                               tzinfo=app.publ_config.timezone)

        with pytest.raises(ValueError):
            utils.parse_date("not a date")
        with pytest.raises(ValueError):
            utils.parse_date("12345678")
        with pytest.raises(ValueError):
            utils.parse_date("")

        assert utils.parse_date('1978-06-14') == (make_date(1978, 6, 14), 'day', utils.DAY_FORMAT)
        assert utils.parse_date('19780614') == (make_date(1978, 6, 14), 'day', utils.DAY_FORMAT)

        assert utils.parse_date('1983-07') == (make_date(1983, 7), 'month', utils.MONTH_FORMAT)
        assert utils.parse_date('198307') == (make_date(1983, 7), 'month', utils.MONTH_FORMAT)

        assert utils.parse_date("1979") == (make_date(1979), 'year', utils.YEAR_FORMAT)

        assert utils.parse_date('19810505_w') == (make_date(1981, 5, 4), 'week', utils.WEEK_FORMAT)
github PlaidWeb / Publ / tests / test_utils.py View on Github external
def test_parse_date():
    """ tests for the date parser """
    import arrow
    from . import PublMock

    app = PublMock()

    with app.app_context():
        def make_date(year=None, month=None, day=None):
            return arrow.Arrow(year=year or 1,
                               month=month or 1,
                               day=day or 1,
                               tzinfo=app.publ_config.timezone)

        with pytest.raises(ValueError):
            utils.parse_date("not a date")
        with pytest.raises(ValueError):
            utils.parse_date("12345678")
        with pytest.raises(ValueError):
            utils.parse_date("")

        assert utils.parse_date('1978-06-14') == (make_date(1978, 6, 14), 'day', utils.DAY_FORMAT)
        assert utils.parse_date('19780614') == (make_date(1978, 6, 14), 'day', utils.DAY_FORMAT)

        assert utils.parse_date('1983-07') == (make_date(1983, 7), 'month', utils.MONTH_FORMAT)
        assert utils.parse_date('198307') == (make_date(1983, 7), 'month', utils.MONTH_FORMAT)

        assert utils.parse_date("1979") == (make_date(1979), 'year', utils.YEAR_FORMAT)

        assert utils.parse_date('19810505_w') == (make_date(1981, 5, 4), 'week', utils.WEEK_FORMAT)