From 71591c0a052e613ba338f403d71e1ee90ff9c464 Mon Sep 17 00:00:00 2001 From: yoshinobc Date: Sun, 24 Apr 2022 17:15:49 +0900 Subject: [PATCH] fix test and update --- optuna_dashboard/_cached_extra_study_property.py | 2 +- python_tests/test_cached_extra_study_property.py | 14 +++++++++++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/optuna_dashboard/_cached_extra_study_property.py b/optuna_dashboard/_cached_extra_study_property.py index e1c8d0ef..5945dfcc 100644 --- a/optuna_dashboard/_cached_extra_study_property.py +++ b/optuna_dashboard/_cached_extra_study_property.py @@ -72,7 +72,7 @@ class _CachedExtraStudyProperty: if trial.state not in states_of_interest: continue - if len(trial.intermediate_values) > 0: + if not self.has_intermediate_values and len(trial.intermediate_values) > 0: self.has_intermediate_values = True current = set([(n, d) for n, d in trial.distributions.items()]) diff --git a/python_tests/test_cached_extra_study_property.py b/python_tests/test_cached_extra_study_property.py index 2ab8395a..09e91c22 100644 --- a/python_tests/test_cached_extra_study_property.py +++ b/python_tests/test_cached_extra_study_property.py @@ -1,3 +1,5 @@ +from typing import Dict +from typing import List from unittest import TestCase import warnings @@ -10,7 +12,7 @@ from optuna.trial import TrialState from optuna_dashboard._cached_extra_study_property import _CachedExtraStudyProperty -class _CachedExtraStudyPropertyTestCase(TestCase): +class _CachedExtraStudyPropertySearchSpaceTestCase(TestCase): def setUp(self) -> None: optuna.logging.set_verbosity(optuna.logging.ERROR) warnings.simplefilter("ignore", category=ExperimentalWarning) @@ -115,8 +117,14 @@ class _CachedExtraStudyPropertyTestCase(TestCase): self.assertEqual(len(cached_extra_study_property.intersection), 0) self.assertEqual(len(cached_extra_study_property.union), 3) + +class _CachedExtraStudyPropertyIntermediateTestCase(TestCase): + def setUp(self) -> None: + optuna.logging.set_verbosity(optuna.logging.ERROR) + warnings.simplefilter("ignore", category=ExperimentalWarning) + def test_no_intermediate_value(self) -> None: - intermediate_values = [ + intermediate_values: List[Dict] = [ {}, {}, ] @@ -171,7 +179,7 @@ class _CachedExtraStudyPropertyTestCase(TestCase): self.assertTrue(cached_extra_study_property.has_intermediate_values) def test_no_trials(self) -> None: - trials = [] + trials: list = [] cached_extra_study_property = _CachedExtraStudyProperty() cached_extra_study_property.update(trials) self.assertFalse(cached_extra_study_property.has_intermediate_values)