Skip to content
Permalink
Browse files
Lint
Signed-off-by: Chris Warrick <kwpolska@gmail.com>
  • Loading branch information
Kwpolska committed Jul 31, 2018
1 parent ee0f73e commit 9ebfc3d4670dc6fbabacf77c89c0922b5b1de94a
Showing with 11 additions and 9 deletions.
  1. +4 −5 nikola/utils.py
  2. +3 −3 tests/base.py
  3. +1 −1 tests/test_integration.py
  4. +3 −0 tests/test_locale.py
@@ -68,8 +68,8 @@
husl = None

try:
import typing
import typing.re
import typing # NOQA
import typing.re # NOQA
except ImportError:
pass

@@ -1187,8 +1187,6 @@ def formatted_date(self, date_format: 'str',
if lang is None:
lang = self.current_lang
locale = self.locales.get(lang, lang)
# For thread-safety
fmt_date = None
# Get a string out of a TranslatableSetting
if isinstance(date_format, TranslatableSetting):
date_format = date_format(lang)
@@ -1203,6 +1201,7 @@ def formatted_date(self, date_format: 'str',

def format_date_in_string(self, message: str, date: datetime.date, lang: 'typing.Optional[str]' = None) -> str:
"""Format date inside a string (message).
Accepted modes: month, month_year, month_day_year.
Format: {month} for standard, {month:MMMM} for customization.
"""
@@ -1217,7 +1216,7 @@ def format_date_in_string(self, message: str, date: datetime.date, lang: 'typing
locale = self.locales.get(lang, lang)

def date_formatter(match: 'typing.re.Match') -> str:
"""A customizable date formatter."""
"""Format a date as requested."""
mode, custom_format = match.groups()
if custom_format:
return babel.dates.format_date(date, custom_format, locale)
@@ -10,11 +10,8 @@


import os
import sys


from contextlib import contextmanager
import locale
import unittest

import logbook
@@ -46,6 +43,7 @@ def cd(path):
yield
os.chdir(old_dir)


LOCALE_DEFAULT = os.environ.get('NIKOLA_LOCALE_DEFAULT', 'en')
LOCALE_OTHER = os.environ.get('NIKOLA_LOCALE_OTHER', 'pl')

@@ -54,6 +52,7 @@ def initialize_localeborg():
nikola.utils.LocaleBorg.reset()
nikola.utils.LocaleBorg.initialize({}, LOCALE_DEFAULT)


class LocaleSupportInTesting(object):
"""
Nikola needs two pairs of valid (language, locale_n) to test multilingual sites.
@@ -81,6 +80,7 @@ def initialize_locales_for_testing(cls, variant):
nikola.utils.LocaleBorg.reset()
nikola.utils.LocaleBorg.initialize({}, 'en')


class FakePost(object):

def __init__(self, title, slug):
@@ -16,7 +16,7 @@
import nikola.plugins.command.init
import nikola.utils

from .base import BaseTestCase, cd, LOCALE_DEFAULT, LOCALE_OTHER, initialize_localeborg
from .base import BaseTestCase, cd, LOCALE_OTHER, initialize_localeborg


class EmptyBuildTest(BaseTestCase):
@@ -13,6 +13,7 @@

DT_PL = '10 lipca 1856 12:34:56 UTC'


@pytest.fixture
def localeborg_base():
"""A base config of LocaleBorg."""
@@ -100,10 +101,12 @@ def test_format_date_translatablesetting(localeborg_base):
assert LocaleBorg().formatted_date(df, TESLA_BIRTHDAY_DT, 'en') == 'en July'
assert LocaleBorg().formatted_date(df, TESLA_BIRTHDAY_DT, 'pl') == 'lipca pl'


def test_format_date_in_string_month(localeborg_base):
assert LocaleBorg().format_date_in_string("Foo {month} Bar", TESLA_BIRTHDAY) == 'Foo July Bar'
assert LocaleBorg().format_date_in_string("Foo {month} Bar", TESLA_BIRTHDAY, 'pl') == 'Foo lipiec Bar'


def test_format_date_in_string_month_year(localeborg_base):
assert LocaleBorg().format_date_in_string("Foo {month_year} Bar", TESLA_BIRTHDAY) == 'Foo July 1856 Bar'
assert LocaleBorg().format_date_in_string("Foo {month_year} Bar", TESLA_BIRTHDAY, 'pl') == 'Foo lipiec 1856 Bar'

0 comments on commit 9ebfc3d

Please sign in to comment.