-
Notifications
You must be signed in to change notification settings - Fork 77
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 #19 from jbigatti/refactor-init-StatsManager
Refactor init stats manager; allow forever booking
- Loading branch information
Showing
4 changed files
with
91 additions
and
20 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
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,49 @@ | ||
from datetime import timedelta | ||
import mock | ||
from unittest import TestCase | ||
import warnings | ||
|
||
from featureforge.experimentation.stats_manager import StatsManager | ||
|
||
DEPRECATION_MSG = ( | ||
'Init arguments will change. ' | ||
'Take a look to http://feature-forge.readthedocs.io/en/latest/experimentation.html' | ||
'#exploring-the-finished-experiments' | ||
) | ||
|
||
DB_CONNECTION_PATH = 'featureforge.experimentation.stats_manager.StatsManager.setup_database_connection' # NOQA | ||
|
||
|
||
class TestStatsManager(TestCase): | ||
|
||
def setUp(self): | ||
self.db_name = 'a_db_name' | ||
self.booking_duration = 10 | ||
|
||
def test_init_with_db_name_as_first_parameter_and_booking_duration_as_second(self): | ||
with mock.patch(DB_CONNECTION_PATH): | ||
st = StatsManager(db_name=self.db_name, booking_duration=self.booking_duration) | ||
self.assertEqual(st._db_config['name'], self.db_name) | ||
self.assertEqual(st.booking_delta, timedelta(seconds=self.booking_duration)) | ||
|
||
def test_if_init_with_db_name_as_second_argument_will_warning(self): | ||
with warnings.catch_warnings(record=True) as w: | ||
# Cause all warnings to always be triggered. | ||
warnings.simplefilter("always", DeprecationWarning) | ||
# Trigger a warning. | ||
with mock.patch(DB_CONNECTION_PATH): | ||
StatsManager(self.booking_duration, self.db_name) | ||
# Verify some things | ||
self.assertEqual(len(w), 1) | ||
self.assertTrue(issubclass(w[-1].category, DeprecationWarning)) | ||
self.assertEqual(str(w[-1].message), DEPRECATION_MSG) | ||
|
||
def test_if_use_db_name_as_second_argument_warnings_but_can_continue(self): | ||
with warnings.catch_warnings(record=True): | ||
# Cause all warnings to always be triggered. | ||
warnings.simplefilter("always", DeprecationWarning) | ||
# Trigger a warning. | ||
with mock.patch(DB_CONNECTION_PATH): | ||
st = StatsManager(self.booking_duration, self.db_name) | ||
self.assertEqual(st._db_config['name'], self.db_name) | ||
self.assertEqual(st.booking_delta, timedelta(seconds=self.booking_duration)) |