Skip to content

Commit

Permalink
test, one day, test lower/upper case and unix timestamp
Browse files Browse the repository at this point in the history
  • Loading branch information
hannhegg committed Mar 26, 2025
1 parent 20710dc commit 7306c5a
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 0 deletions.
26 changes: 26 additions & 0 deletions tests/unit/test_letter_one_day.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import unittest
import sys
import os

# Add the src folder to the Python path
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '../../src')))

from my_package.fetch_current_data import fetch_current_data

class TestCityNameCase(unittest.TestCase):

def test_city_name_case_insensitive(self):
# Test city with big and small letter
city_name_upper = "Oslo"
city_name_lower = "oslo"

# Test if they return the same, the underscore is for the folder that we dont use here
data_upper, _ = fetch_current_data(city_name_upper)
data_lower, _ = fetch_current_data(city_name_lower)

# use temperature as an example to see if data is identical
self.assertEqual(data_upper["main"]["temp"], data_lower["main"]["temp"])

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

39 changes: 39 additions & 0 deletions tests/unit/test_one_day.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import unittest
import sys
import os
from datetime import datetime
from src.my_package.date_to_unix import from_unix_timestamp

# This will make the absolute path from the root of the project, and will therefor work every time
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "../../src")))


class TestGetUnixTimestamp(unittest.TestCase):

def test_get_unix_timestamp(self):
# Example user input for start and end date
start_date_input = "2000, 03, 05, 11, 00"
end_date_input = "2000, 03, 05, 13, 00"

# Convert input string to datetime object
start_date = datetime.strptime(start_date_input, "%Y, %m, %d, %H, %M")
end_date = datetime.strptime(end_date_input, "%Y, %m, %d, %H, %M")

# Get the Unix timestamp by calling .timestamp()
expected_unix_start = int(start_date.timestamp())
expected_unix_end = int(end_date.timestamp())

# Call the function directly with test data
function_unix_start, function_unix_end = from_unix_timestamp(expected_unix_start, expected_unix_end)

# Assert that the returned timestamps are correct
self.assertEqual(function_unix_start, start_date)
self.assertEqual(function_unix_end, end_date)


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


#this test is to test if the code date matches its timestamp

0 comments on commit 7306c5a

Please sign in to comment.