From 4fb95666ba6d7d5a50550e72b1d3cbf5577e082f Mon Sep 17 00:00:00 2001 From: Moin Date: Tue, 27 Dec 2016 04:51:43 +0530 Subject: [PATCH 1/6] properties test at single place --- test_maya.py | 48 ++++++++++++++++++++++++------------------------ 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/test_maya.py b/test_maya.py index 32a00cc..c9b7678 100644 --- a/test_maya.py +++ b/test_maya.py @@ -49,14 +49,30 @@ def test_dt_tz_naive(): def test_random_date(): - d = maya.when('11-17-11 08:09:10') - assert d.year == 2011 - assert d.month == 11 - assert d.day == 17 - assert d.hour == 8 - assert d.minute == 9 - assert d.second == 10 - assert d.microsecond == 0 + + # Test properties for maya.when() + d1 = maya.when('11-17-11 08:09:10') + assert d1.year == 2011 + assert d1.month == 11 + assert d1.day == 17 + assert d1.week == 46 + assert d1.weekday == 4 + assert d1.hour == 8 + assert d1.minute == 9 + assert d1.second == 10 + assert d1.microsecond == 0 + + # Test properties for maya.parse() + d2 = maya.parse('February 29, 1992 13:12:34') + assert d2.year == 1992 + assert d2.month == 2 + assert d2.day == 29 + assert d2.week == 9 + assert d2.weekday == 6 + assert d2.hour == 13 + assert d2.minute == 12 + assert d2.second == 34 + assert d2.microsecond == 0 def test_print_date(capsys): @@ -120,19 +136,3 @@ def test_comparison_operations(): assert (now >= now_copy) is True assert (now >= tomorrow) is False - - -def test_weekday(): - dt = maya.parse('February 21, 1994') - assert dt.weekday == 1 # was a Monday - - dt = maya.parse('February 29, 1992') - assert dt.weekday == 6 # was a Saturday - - -def test_week(): - dt = maya.parse('February 21, 1994') - assert dt.week == 8 - - dt = maya.parse('May 29, 1992') - assert dt.week == 22 From edfb9baae42b22409b198d9f10c70e70be4ff909 Mon Sep 17 00:00:00 2001 From: Moin Date: Tue, 27 Dec 2016 04:34:49 +0530 Subject: [PATCH 2/6] use local timezone to get the slang date --- maya.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/maya.py b/maya.py index b630640..e5f355a 100644 --- a/maya.py +++ b/maya.py @@ -213,7 +213,8 @@ class MayaDT(object): def slang_date(self): """"Returns human slang representation of date.""" - return humanize.naturaldate(self.datetime()) + dt = self.datetime(naive=True, to_timezone=self.local_timezone) + return humanize.naturaldate(dt) def slang_time(self): """"Returns human slang representation of time.""" From d6b8ac54ad2dc5ad1516ad8983df74011324d835 Mon Sep 17 00:00:00 2001 From: Joshua Li Date: Tue, 27 Dec 2016 21:24:02 -0500 Subject: [PATCH 3/6] README.rst is now read correctly with utf-8 encoding into the setup long_description, fixes python3 windows cmd installs via pip --- setup.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/setup.py b/setup.py index 7471f13..a2a660d 100755 --- a/setup.py +++ b/setup.py @@ -16,8 +16,9 @@ except ImportError: here = os.path.abspath(dirname(__file__)) -def read(*parts): - return codecs.open(os.path.join(here, *parts), 'r').read() +with codecs.open(os.path.join(here, 'README.rst'), encoding='utf-8') as f: + long_description = '\n' + f.read() + if sys.argv[-1] == "publish": os.system("python setup.py sdist bdist_wheel upload") @@ -37,7 +38,7 @@ setup( name='maya', version='0.1.4', description='Datetimes for Humans.', - long_description= '\n' + read('README.rst'), + long_description=long_description, author='Kenneth Reitz', author_email='me@kennethreitz.com', url='https://github.com/kennethreitz/maya', From 82d20ad1dcbf1612f58df13b161f621627cbd68d Mon Sep 17 00:00:00 2001 From: Joshua Li Date: Tue, 27 Dec 2016 22:32:39 -0500 Subject: [PATCH 4/6] fix erroneous test logic with dt_tz_naive and dt_tz_translation --- test_maya.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test_maya.py b/test_maya.py index 32a00cc..648bc31 100644 --- a/test_maya.py +++ b/test_maya.py @@ -36,7 +36,7 @@ def test_machine_parse(): def test_dt_tz_translation(): d1 = maya.now().datetime() d2 = maya.now().datetime(to_timezone='US/Eastern') - assert d1.hour - d2.hour == 5 + assert (d1.hour - d2.hour) % 24 == 5 def test_dt_tz_naive(): @@ -45,7 +45,7 @@ def test_dt_tz_naive(): d2 = maya.now().datetime(to_timezone='US/Eastern', naive=True) assert d2.tzinfo is None - assert d1.hour - d2.hour == 5 + assert (d1.hour - d2.hour) % 24 == 5 def test_random_date(): From c17a358c66cfb22919bb2aeb10a72dfdf0ad19a7 Mon Sep 17 00:00:00 2001 From: Timo Furrer Date: Tue, 27 Dec 2016 09:52:22 +0100 Subject: [PATCH 5/6] Support Python 3.3, 3.4, 3.5, 3.6 ruamel.ordereddict is only needed for python 2.7 anyway. So we should not depend on it in requirements.txt --- .travis.yml | 10 +++++++--- requirements.txt | 5 +++-- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/.travis.yml b/.travis.yml index 197b11b..c3afb2b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,8 +1,12 @@ language: python python: - "2.7" - # - "3.5" # looks like ruamel.ordereddict doesn't build for python3 + - "3.3" + - "3.4" + - "3.5" + - "3.6" + # command to install dependencies -install: "pip install -r requirements.txt" +install: pip install -r requirements.txt # command to run tests -script: make \ No newline at end of file +script: make diff --git a/requirements.txt b/requirements.txt index ed6b7f0..9878b9d 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,4 @@ --e . +-e . dateparser==0.5.0 humanize==0.5.1 iso8601==0.1.11 @@ -8,7 +8,8 @@ pytest==3.0.5 python-dateutil==2.6.0 pytz==2016.10 regex==2016.11.21 -ruamel.ordereddict==0.4.9 +#ruamel.ordereddict is only needed for python 2 +#ruamel.ordereddict==0.4.9 ruamel.yaml==0.13.4 six==1.10.0 typing==3.5.2.2 From 2f47366cbf50fde372bbe52bb3339d6434bc991d Mon Sep 17 00:00:00 2001 From: Timo Furrer Date: Wed, 28 Dec 2016 09:12:48 +0100 Subject: [PATCH 6/6] Implement str protocol for human readable datetime printing --- maya.py | 3 +++ test_maya.py | 4 +++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/maya.py b/maya.py index b630640..8bee151 100644 --- a/maya.py +++ b/maya.py @@ -46,6 +46,9 @@ class MayaDT(object): def __repr__(self): return ''.format(self._epoch) + def __str__(self): + return self.rfc2822() + def __format__(self, *args, **kwargs): """Return's the datetime's format""" return format(self.datetime(), *args, **kwargs) diff --git a/test_maya.py b/test_maya.py index 32a00cc..d52ee3a 100644 --- a/test_maya.py +++ b/test_maya.py @@ -64,7 +64,9 @@ def test_print_date(capsys): print(d) out, err = capsys.readouterr() - assert out == '\n' + + assert out == 'Thu, 17 Nov 2011 00:00:00 GMT\n' + assert repr(d) == '' def test_invalid_date():