Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat tests #1

Merged
merged 2 commits into from
Feb 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()
Loading