Skip to content

Commit

Permalink
Merge pull request #1 from nrjadkry/feat-tests
Browse files Browse the repository at this point in the history
Feat tests
  • Loading branch information
nrjadkry authored Feb 6, 2024
2 parents d59d771 + da5a71a commit 33f82d1
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 5 deletions.
8 changes: 3 additions & 5 deletions nepali_date_utils/date_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ def convert_to_bs(self, day_data):
bs_date["year"] -= 1
bs_date["month"] = 12
bs_date["day"] = day_count
return f"{bs_date['year']}/{bs_date['month']}/{bs_date['day']}"

return bs_date
except KeyError:
raise ValueError("Date out of range")
Expand Down Expand Up @@ -122,12 +124,8 @@ def offset_ad_days(self, day_count):
self.reference_ad["day"],
)
offset_date = base_date + timedelta(days=day_count)
return offset_date.date().strftime("%Y/%m/%d")

month = offset_date.month

date_obj = {"year": offset_date.year, "month": month, "day": offset_date.day}

return date_obj

@classmethod
def ad_to_bs(cls, date_str):
Expand Down
Empty file added tests/__init__.py
Empty file.
26 changes: 26 additions & 0 deletions tests/test_date_converter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import sys
import unittest
from os.path import dirname, join, abspath

sys.path.insert(0, abspath(join(dirname(__file__), '..')))

from nepali_date_utils.date_converter import converter

class TestDateConverter(unittest.TestCase):

# Test data sets
test_data = [
{"bs_date": "2054/04/1", "ad_date": "1997/07/16"},
{"bs_date": "2055/09/15", "ad_date": "1998/12/30"},
{"bs_date": "2077/04/20", "ad_date": "2020/08/04"},
]

def test_bs_to_ad(self):
for data in self.test_data:
bs_date = data["bs_date"]
expected_ad_date = data["ad_date"]
actual_ad_date = converter.bs_to_ad(bs_date)
self.assertEqual(actual_ad_date, expected_ad_date)

if __name__ == '__main__':
unittest.main()

0 comments on commit 33f82d1

Please sign in to comment.