Skip to content

Commit

Permalink
Tests: minor tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
eledhwen committed Oct 8, 2023
1 parent 56f569b commit 3bab18c
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions tests/test_custom_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ def out(self, data: EmissionsData):
class TestCarbonCustomHandler(unittest.TestCase):
def setUp(self) -> None:
self.project_name = "project_TestCarbonCustomHandler"
self.emissions_logfile = "emissions-test-TestCarbonCustomHandler.log"

def test_carbon_tracker_custom_handler(self):
handler_0 = CustomOutput()
Expand All @@ -45,8 +44,8 @@ def test_carbon_tracker_custom_handler(self):
assert isinstance(emissions, float)
self.assertNotEqual(emissions, 0.0)
self.assertAlmostEqual(emissions, 6.262572537957655e-05, places=2)
self.verify_logging_output(handler_0)
self.verify_logging_output(handler_1)
self.verify_custom_handler_state(handler_0)
self.verify_custom_handler_state(handler_1)

def test_decorator_flush(self):
handler_0 = CustomOutput()
Expand All @@ -60,14 +59,13 @@ def test_decorator_flush(self):
)
def dummy_train_model():
heavy_computation(run_time_secs=1)
# I don't know how to call flush() in decorator mode
return 42

dummy_train_model()
self.verify_logging_output(handler_0)
self.verify_logging_output(handler_1)
self.verify_custom_handler_state(handler_0)
self.verify_custom_handler_state(handler_1)

def verify_logging_output(self, handler: CustomOutput, expected_lines=1) -> None:
def verify_custom_handler_state(self, handler: CustomOutput, expected_lines=1) -> None:
assert len(handler.log) == expected_lines
results = handler.log[0]
self.assertEqual(results.project_name, self.project_name)
Expand Down

0 comments on commit 3bab18c

Please sign in to comment.