Skip to content

Commit

Permalink
remove check_int_field
Browse files Browse the repository at this point in the history
  • Loading branch information
mhajiloo committed Oct 28, 2020
1 parent 082fb68 commit 44ec964
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 32 deletions.
7 changes: 4 additions & 3 deletions persiantools/jdatetime.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-
import sys
from datetime import date, timedelta, tzinfo, time as _time, datetime as dt
import operator

from persiantools import digits, utils, PY2

Expand Down Expand Up @@ -160,9 +161,9 @@ def locale(self, locale):

@classmethod
def _check_date_fields(cls, year, month, day, locale):
year = utils.check_int_field(year)
month = utils.check_int_field(month)
day = utils.check_int_field(day)
year = operator.index(year)
month = operator.index(month)
day = operator.index(day)

if not MINYEAR <= year <= MAXYEAR:
raise ValueError("year must be in %d..%d" % (MINYEAR, MAXYEAR), year)
Expand Down
20 changes: 0 additions & 20 deletions persiantools/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,3 @@ def replace(string, dictionary):

pattern = re.compile("|".join(dictionary.keys()))
return pattern.sub(lambda x: dictionary[x.group()], string)


def check_int_field(value):
if isinstance(value, int):
return value

if not isinstance(value, float):
try:
value = value.__int__()
except AttributeError:
pass
else:
if isinstance(value, int):
return value

raise TypeError("__int__ returned non-int (type %s)" % type(value).__name__)

raise TypeError("an integer is required (got type %s)" % type(value).__name__)

raise TypeError("integer argument expected, got float")
9 changes: 0 additions & 9 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,3 @@ def test_replace(self):
),
u"اایی بس که نباشیم و جهان خخووااههدد بود",
)

def test_int(self):
self.assertEqual(utils.check_int_field(100010001), 100010001)

with pytest.raises(TypeError):
utils.check_int_field(1111.9999)

with pytest.raises(TypeError):
utils.check_int_field("1000")

0 comments on commit 44ec964

Please sign in to comment.