def test_to_dict_metric_factory(self, build_mock): metric = metrics.MetricFactory build_mock.return_value = metrics.Metric('test') out = metrics.to_dict(metric)().build() self.assertTrue(out.metric.name == 'test') self.assertTrue(isinstance(out, metrics.ToDict)) build_mock.assert_called_once()
def test_std_metric_instance(self): metric = metrics.Metric('test') out = metrics.std(metric) self.assertTrue(isinstance(out, metrics.MetricTree)) self.assertTrue(isinstance(out.children[0], metrics.ToDict)) self.assertTrue(isinstance(out.children[0].metric, metrics.Std)) self.assertTrue(out.children[0].metric.name == 'test_std') self.assertTrue(out.root.name == 'test')
def test_mean_metric_instance(self): metric = metrics.Metric('test') out = metrics.mean(metric, dim=10) self.assertTrue(isinstance(out, metrics.MetricTree)) self.assertTrue(isinstance(out.children[0], metrics.ToDict)) self.assertTrue(isinstance(out.children[0].metric, metrics.Mean)) self.assertTrue(out.children[0].metric._kwargs['dim'] == 10) self.assertTrue(out.children[0].metric.name == 'test') self.assertTrue(out.root.name == 'test')
def test_std_metric_factory(self, build_mock): metric = metrics.MetricFactory build_mock.return_value=metrics.Metric('test') out = metrics.std(metric)().build() self.assertTrue(isinstance(out, metrics.MetricTree)) self.assertTrue(isinstance(out.children[0], metrics.ToDict)) self.assertTrue(isinstance(out.children[0].metric, metrics.Std)) self.assertTrue(out.children[0].metric.name == 'test_std') self.assertTrue(out.root.name == 'test')
def test_running_mean_metric_factory(self, build_mock): metric = metrics.MetricFactory build_mock.return_value=metrics.Metric('test') out = metrics.running_mean(metric)().build() self.assertTrue(isinstance(out, metrics.MetricTree)) self.assertTrue(isinstance(out.children[0], metrics.ToDict)) self.assertTrue(isinstance(out.children[0].metric, metrics.RunningMean)) self.assertTrue(out.children[0].metric.name == 'running_test') self.assertTrue(out.root.name == 'test')
def test_running_mean_metric_instance(self): metric = metrics.Metric('test') out = metrics.running_mean(batch_size=40, step_size=20)(metric) self.assertTrue(isinstance(out, metrics.MetricTree)) self.assertTrue(isinstance(out.children[0], metrics.ToDict)) self.assertTrue(isinstance(out.children[0].metric, metrics.RunningMean)) self.assertTrue(out.children[0].metric._batch_size == 40) self.assertTrue(out.children[0].metric._step_size == 20) self.assertTrue(out.children[0].metric.name == 'running_test') self.assertTrue(out.root.name == 'test')
def test_std_metric_instance(self): metric = metrics.Metric('test') out = metrics.std(metric, dim=10, unbiased=False) self.assertTrue(isinstance(out, metrics.MetricTree)) self.assertTrue(isinstance(out.children[0], metrics.ToDict)) self.assertTrue(isinstance(out.children[0].metric, metrics.Std)) self.assertTrue(out.children[0].metric._kwargs['dim'] == 10) self.assertTrue(not out.children[0].metric._unbiased) self.assertTrue(out.children[0].metric.name == 'test_std') self.assertTrue(out.root.name == 'test')
def test_to_dict_metric_instance(self): metric = metrics.Metric('test') out = metrics.to_dict(metric) self.assertTrue(out.metric.name == 'test') self.assertTrue(isinstance(out, metrics.ToDict))