Skip to content

Commit

Permalink
Merge branch 'sarthakmadaan-add_tests'
Browse files Browse the repository at this point in the history
  • Loading branch information
asadurski committed Feb 8, 2018
2 parents 84b8fe8 + 92b5c83 commit 42dd7c6
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
8 changes: 8 additions & 0 deletions tests/test_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,3 +137,11 @@ def test_error_is_raised_when_none_is_passed_in_settings(self):

with self.assertRaisesRegexp(TypeError, 'Invalid.*None\}'):
test_func(settings={'TO_TIMEZONE': None})

def test_error_is_raised_for_invalid_type_settings(self):
test_func = apply_settings(test_function)
try:
test_func(settings=['current_period', False, 'current'])
except Exception as error:
self.error = error
self.then_error_was_raised(TypeError, ["settings can only be either dict or instance of Settings class"])
27 changes: 26 additions & 1 deletion tests/test_timezone_parser.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
# -*- coding: utf-8 -*-
from datetime import datetime, timedelta
from pytz import timezone

from mock import Mock, patch
from parameterized import parameterized, param

import dateparser.timezone_parser
from dateparser.timezone_parser import pop_tz_offset_from_string, get_local_tz_offset
from dateparser.timezone_parser import pop_tz_offset_from_string, get_local_tz_offset, StaticTzInfo
from dateparser import parse
from tests import BaseTestCase

Expand Down Expand Up @@ -159,3 +160,27 @@ def when_date_is_parsed(self, datestring):

def then_date_is(self, date):
self.assertEqual(date, self.result)

class TestStaticTzInfo(BaseTestCase):
def setUp(self):
super(TestStaticTzInfo, self).setUp()

@parameterized.expand([
param(given_date=datetime(2007, 1, 18, tzinfo=timezone('UTC'))),
param(given_date=datetime(2003, 3, 31, tzinfo=timezone('US/Arizona'))),
param(given_date=datetime(2000, 2, 20, tzinfo=timezone('Pacific/Samoa'))),
])
def test_localize_raises_error_if_date_has_tzinfo(self, given_date):
self.timezone_info = StaticTzInfo('UTC\\+00:00', timedelta(0))
self.when_date_is_localized(given_date)
self.then_error_was_raised(ValueError, ['Not naive datetime (tzinfo is already set)'])

def when_date_is_localized(self, given_date):
try:
self.localized_date = self.timezone_info.localize(given_date)
except Exception as error:
self.error = error

def then_localized_date_is(self, expected_date, expected_tzname):
self.assertEqual(self.localized_date.date(), expected_date.date())
self.assertEqual(self.localized_date.tzname(), expected_tzname)

0 comments on commit 42dd7c6

Please sign in to comment.