Skip to content

Commit

Permalink
Lint
Browse files Browse the repository at this point in the history
Signed-off-by: Chris Warrick <kwpolska@gmail.com>
  • Loading branch information
Kwpolska committed Jul 31, 2018
1 parent ee0f73e commit 9ebfc3d
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 9 deletions.
9 changes: 4 additions & 5 deletions nikola/utils.py
Expand Up @@ -68,8 +68,8 @@
husl = None

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

Expand Down Expand Up @@ -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)
Expand All @@ -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.
"""
Expand All @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions tests/base.py
Expand Up @@ -10,11 +10,8 @@


import os
import sys


from contextlib import contextmanager
import locale
import unittest

import logbook
Expand Down Expand Up @@ -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')

Expand All @@ -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.
Expand Down Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion tests/test_integration.py
Expand Up @@ -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):
Expand Down
3 changes: 3 additions & 0 deletions tests/test_locale.py
Expand Up @@ -13,6 +13,7 @@

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


@pytest.fixture
def localeborg_base():
"""A base config of LocaleBorg."""
Expand Down Expand Up @@ -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'
Expand Down

0 comments on commit 9ebfc3d

Please sign in to comment.