From 9831d01c2d847d13531a70d0028e7ec7bde787bb Mon Sep 17 00:00:00 2001 From: sarimbinwaseem Date: Fri, 23 Feb 2024 16:42:36 +0500 Subject: [PATCH] tests included. --- .github/workflows/salah_test.yaml | 22 ++++++++++++++++++++++ Utils/salahtime.py | 8 ++++---- salah_timings_test.py | 22 ++++++++++++++++++++++ 3 files changed, 48 insertions(+), 4 deletions(-) create mode 100644 .github/workflows/salah_test.yaml create mode 100644 salah_timings_test.py diff --git a/.github/workflows/salah_test.yaml b/.github/workflows/salah_test.yaml new file mode 100644 index 0000000..23f79c4 --- /dev/null +++ b/.github/workflows/salah_test.yaml @@ -0,0 +1,22 @@ +name: Unit Test + +on: [push] + +jobs: + build: + runs-on: ubuntu-latest + strategy: + matrix: + python-version: ["3.11", "3.12"] + steps: + - uses: actions/checkout@v3 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v3 + with: + python-version: ${{ matrix.python-version }} + # - name: Install dependencies + # run: | + # python -m pip install --upgrade pip + # pip install -r windows-requirements.txt + - name: Testing + run: python salah_timings_test.py \ No newline at end of file diff --git a/Utils/salahtime.py b/Utils/salahtime.py index efde48c..2065079 100755 --- a/Utils/salahtime.py +++ b/Utils/salahtime.py @@ -26,7 +26,7 @@ def __init__(self): self.check_changes_flag = True # Indexes where the data is - self._FAJIR = 2 + self._FAJAR = 2 self._TULU = 3 self._ZUHUR = 5 self._ASAR = 6 @@ -100,7 +100,7 @@ def _number2month(self, number): def _get_salah_time(self) -> datetime.time: salah_times = ( - self._today_data[self._FAJIR], + self._today_data[self._FAJAR], self._today_data[self._TULU], self._today_data[self._ZUHUR], self._today_data[self._ASAR], @@ -119,7 +119,7 @@ def _get_salah_time(self) -> datetime.time: with shelve.open(f"Times/{self.month}") as db: next_day_data = db[str(self.current_date.day + 1)] - salah_time = next_day_data[self._FAJIR] + salah_time = next_day_data[self._FAJAR] except KeyError: # Possible month change. current_month_number = self.current_date.strftime("%m").replace("0", "") @@ -128,7 +128,7 @@ def _get_salah_time(self) -> datetime.time: with shelve.open(f"Times/{next_month_name}") as db: next_day_data = db[str(1)] - salah_time = next_day_data[self._FAJIR] + salah_time = next_day_data[self._FAJAR] return salah_time diff --git a/salah_timings_test.py b/salah_timings_test.py new file mode 100644 index 0000000..988d410 --- /dev/null +++ b/salah_timings_test.py @@ -0,0 +1,22 @@ +from Utils.salahtime import SalahTime +import datetime + +st = SalahTime() + +def test_num2month() -> None: + month = st._number2month(2) + assert month == "February" + +def test_time2display() -> None: + + date = datetime.datetime(2024, 1, 1, 14, 25).time() + res = st._time2display(date) + print(res) + + assert type(res) is str + assert res == "02:25 PM" + +def test_getalltimes() -> None: + res = st.get_all_times() + assert type(res) is tuple +