Skip to content


Subversion checkout URL

You can clone with
Download ZIP


Raise TypeErrors for invalid argument types. #8

merged 2 commits into from

2 participants


No description provided.

@nvie nvie merged commit 11a6f98 into nvie:master

1 check passed

Details default The Travis build passed


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 6 additions and 10 deletions.
  1. +3 −3 tests/
  2. +3 −7 times/
6 tests/
@@ -102,7 +102,7 @@ def test_to_universal_rejects_no_tzinfo(self): # noqa
def test_to_universal_rejects_non_date_arguments(self):
"""to_universal rejects non-date arguments"""
- with self.assertRaises(ValueError):
+ with self.assertRaises(TypeError):
times.to_universal([1, 2, 3])
@@ -127,7 +127,7 @@ def test_convert_unix_time_to_datetime(self): # noqa
def test_convert_non_numeric_from_unix(self):
"""from_unix refuses to accept non-numeric input"""
- with self.assertRaises(ValueError):
+ with self.assertRaises(TypeError):
@@ -141,7 +141,7 @@ def test_convert_datetime_to_unix_time(self): # noqa
def test_convert_non_numeric_to_unix(self):
"""to_unix refuses to accept non-numeric input"""
- with self.assertRaises(ValueError):
+ with self.assertRaises(TypeError):
10 times/
@@ -36,7 +36,7 @@ def to_universal(local_dt, timezone=None):
def from_local(local_dt, timezone=None):
"""Converts the given local datetime to a universal datetime."""
if not isinstance(local_dt, datetime.datetime):
- raise ValueError('First argument should be int, float or datetime.')
+ raise TypeError('Expected a datetime object')
if timezone is not None:
if local_dt.tzinfo is not None:
@@ -63,9 +63,7 @@ def from_unix(ut):
time. Assumes the input is in UTC, as `time.time()` does.
if not isinstance(ut, (int, float)):
- raise ValueError(
- 'First argument to from_unix should be an int or float'
- )
+ raise TypeError('Expected an int or float value')
return datetime.datetime.utcfromtimestamp(float(ut))
@@ -85,9 +83,7 @@ def to_local(dt, timezone):
def to_unix(dt):
"""Converts a datetime object to unixtime"""
if not isinstance(dt, datetime.datetime):
- raise ValueError(
- 'First argument to to_unix should be a datetime object'
- )
+ raise TypeError('Expected a datetime object')
return calendar.timegm(dt.utctimetuple())
Something went wrong with that request. Please try again.