-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test, one day, test lower/upper case and unix timestamp
- Loading branch information
Showing
2 changed files
with
65 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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() | ||
|
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
|
|