-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #74 from LDAR-Sim/73-feat-initialize-number-of-leaks
73 feat initialize number of leaks
- Loading branch information
Showing
8 changed files
with
175 additions
and
12 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
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
Empty file.
83 changes: 83 additions & 0 deletions
83
LDAR_Sim/testing/unit_testing/test_initialization/test_leaks/leak_testing_fixtures.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
""" Fixtures for testing leaks""" | ||
|
||
import pytest | ||
from datetime import datetime | ||
from typing import Any, Dict | ||
|
||
|
||
@pytest.fixture(name="mock_program") | ||
def mock_program_fix(): | ||
return { | ||
'subtype_file': None, | ||
'NRd': 10, | ||
'n_init_leaks': None, | ||
'n_init_days': None, | ||
'start_date': (2022, 1, 1), | ||
'emissions': { | ||
'LPR': 0.5, | ||
'leak_file': None, | ||
}, | ||
'leak_rate_source': 'sample', | ||
'empirical_leak_rates': [1], | ||
|
||
} | ||
|
||
|
||
@pytest.fixture(name="mock_program_2") | ||
def mock_program_2_fix(): | ||
return { | ||
'subtype_file': None, | ||
'NRd': 10, | ||
'n_init_leaks': 1, | ||
'n_init_days': 10, | ||
'start_date': (2022, 1, 1), | ||
'emissions': { | ||
'LPR': 0.5, | ||
'leak_file': None, | ||
}, | ||
'leak_rate_source': 'sample', | ||
'empirical_leak_rates': [1], | ||
} | ||
|
||
|
||
@pytest.fixture(name="mock_site_for_leak_test") | ||
def mock_site_for_leak_test_fix() -> Dict[str, Any]: | ||
return { | ||
'facility_ID': 'test', | ||
'equipment_groups': 1, | ||
'empirical_leak_rates': [1], | ||
'lat': 52.0, | ||
'lon': -114.0, | ||
'leak_rate_source': 'sample', | ||
} | ||
|
||
|
||
@pytest.fixture(name="mock_site_return_test") | ||
def mock_site_return_test_fix() -> list[Dict[str, Any]]: | ||
return [{ | ||
'leak_ID': 'test_0000000001', | ||
'facility_ID': 'test', | ||
'equipment_group': 0, | ||
'rate': 1, | ||
'lat': 52.0, | ||
'lon': -114.0, | ||
'status': 'active', | ||
'days_active': 0, | ||
'volume': None, | ||
'estimated_volume': None, | ||
'estimated_volume_b': None, | ||
'measured_rate': None, | ||
'tagged': False, | ||
'component': 'unknown', | ||
'date_began': datetime(2022, 1, 1, 0, 0), | ||
'day_ts_began': 0, | ||
'estimated_date_began': None, | ||
'date_tagged': None, | ||
'tagged_by_company': None, | ||
'tagged_by_crew': None, | ||
'init_detect_by': None, | ||
'init_detect_date': None, | ||
'requires_shutdown': False, | ||
'date_repaired': None, | ||
'repair_delay': None, | ||
}] |
33 changes: 33 additions & 0 deletions
33
LDAR_Sim/testing/unit_testing/test_initialization/test_leaks/test_generate_init_leaks.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
""" | ||
Module to test generate_initial_leaks | ||
""" | ||
|
||
from src.initialization.leaks import generate_initial_leaks | ||
from testing.unit_testing.test_initialization.test_leaks.leak_testing_fixtures import ( | ||
mock_site_for_leak_test_fix, | ||
mock_site_return_test_fix, | ||
mock_program_fix, | ||
mock_program_2_fix, | ||
) | ||
|
||
|
||
def test_042_initialize_leaks(mock_site_for_leak_test, mock_program, mock_site_return_test, mocker): | ||
mocker.patch('src.initialization.leaks.random.binomial', return_value=1) | ||
mocker.patch('src.initialization.leaks.random.randint', return_value=0) | ||
|
||
# Call the function under test | ||
result = generate_initial_leaks(mock_program, mock_site_for_leak_test) | ||
|
||
# Assert the expected result | ||
assert result == mock_site_return_test | ||
|
||
|
||
def test_042_initialize_leaks_2(mock_site_for_leak_test, mock_program_2, mock_site_return_test, mocker): | ||
mocker.patch('src.initialization.leaks.random.binomial', return_value=1) | ||
mocker.patch('src.initialization.leaks.random.randint', return_value=0) | ||
|
||
# Call the function under test | ||
result = generate_initial_leaks(mock_program_2, mock_site_for_leak_test) | ||
|
||
# Assert the expected result | ||
assert result == mock_site_return_test |
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
[pytest] | ||
python_files = test_*.py | ||
pythonpath = LDAR_Sim/src LDAR_Sim/external_sensors | ||
|