This repository has been archived by the owner on May 9, 2024. It is now read-only.
-
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.
- Loading branch information
Showing
3 changed files
with
61 additions
and
1 deletion.
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,20 @@ | ||
name: Python unittest | ||
|
||
on: [push] | ||
|
||
jobs: | ||
test: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Set up Python | ||
uses: actions/setup-python@v4 | ||
with: | ||
python-version: '3.11' | ||
- name: Install dependencies | ||
run: | | ||
python -m pip install --upgrade pip | ||
pip install -r requirements.txt | ||
- name: Running tests | ||
run: | | ||
python -m unittest discover -p '*_test.py' |
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
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,40 @@ | ||
import unittest | ||
from datetime import datetime | ||
|
||
from cloud_function.replay_from_bigquery import TimeConfig | ||
|
||
|
||
class TestTimeConfig(unittest.TestCase): | ||
config = TimeConfig( | ||
real_start_time=datetime.fromtimestamp(4000).isoformat(), | ||
simulation_start_time=datetime.fromtimestamp(10000).isoformat(), | ||
simulation_end_time=datetime.fromtimestamp(20000).isoformat(), | ||
speed=2, | ||
scheduler_name="" | ||
) | ||
|
||
def test_is_before_simulation(self): | ||
self.assertEqual(self.config.is_before_simulation(datetime.fromtimestamp(12000)), False) | ||
self.assertEqual(self.config.is_before_simulation(datetime.fromtimestamp(10000)), False) | ||
self.assertEqual(self.config.is_before_simulation(datetime.fromtimestamp(6000)), False) | ||
self.assertEqual(self.config.is_before_simulation(datetime.fromtimestamp(4000)), False) | ||
self.assertEqual(self.config.is_before_simulation(datetime.fromtimestamp(2000)), True) | ||
self.assertEqual(self.config.is_before_simulation(datetime.fromtimestamp(3999)), True) | ||
|
||
def test_is_after_simulation(self): | ||
self.assertEqual(self.config.is_after_simulation(datetime.fromtimestamp(12000)), True) | ||
self.assertEqual(self.config.is_after_simulation(datetime.fromtimestamp(10000)), True) | ||
self.assertEqual(self.config.is_after_simulation(datetime.fromtimestamp(9000)), True) | ||
self.assertEqual(self.config.is_after_simulation(datetime.fromtimestamp(8999)), False) | ||
self.assertEqual(self.config.is_after_simulation(datetime.fromtimestamp(2000)), False) | ||
self.assertEqual(self.config.is_after_simulation(datetime.fromtimestamp(3999)), False) | ||
|
||
def test_get_simulation_time(self): | ||
self.assertEqual(self.config.get_simulation_time(datetime.fromtimestamp(4000)), datetime.fromtimestamp(10000)) | ||
self.assertEqual(self.config.get_simulation_time(datetime.fromtimestamp(4001)), datetime.fromtimestamp(10002)) | ||
self.assertEqual(self.config.get_simulation_time(datetime.fromtimestamp(6000)), datetime.fromtimestamp(14000)) | ||
self.assertEqual(self.config.get_simulation_time(datetime.fromtimestamp(9000)), datetime.fromtimestamp(20000)) | ||
|
||
|
||
if __name__ == '__main__': | ||
unittest.main() |