def test_equality_behaviour(self): m_a = MetricData('name', self.messages, self.dimensions) m_b = MetricData('name', self.messages, self.dimensions) self.assertEqual(m_a, m_b) m_a = MetricData('name', self.messages, self.dimensions) m_b = MetricData('not-name', self.messages, self.dimensions) self.assertNotEqual(m_a, m_b) m_a = MetricData('name', {'a': 1}, self.dimensions) m_b = MetricData('name', {'b': 2}, self.dimensions) self.assertEqual( m_a, m_b, 'Message dictionaries should not ' 'affect equality of MetricData instances') m_a = MetricData('name', self.messages, self.dimensions) m_b = MetricData('name', self.messages, {}) self.assertNotEqual(m_a, m_b) m_a = MetricData('name', self.messages, self.dimensions) m_b = MetricData('name', self.messages, self.dimensions) m_a.message = 'ok' m_b.message = 'fail' self.assertNotEqual(m_a, m_b) m_a = MetricData('name', self.messages, self.dimensions) m_b = MetricData('name', self.messages, self.dimensions) m_a.value = 1 m_b.value = 2 self.assertNotEqual(m_a, m_b)
def test_message(self): r = MetricData(name='name', messages={ 'ok': 'test message', 'test': 'test with meta {test_value} and {test_value2}', }) # Test automatic message assignment when a the Status Enum is used # as the value self.assertEqual('', r.message) r.value = Severity.ok self.assertEqual('test message', r.message) # Test that an error is raised when trying to use a message without # providing all of the dimension values first. with self.assertRaisesRegexp(ValueError, 'requires a dimension or'): r.message = 'test' r['test_value'] = '123' r.msgkey('test_value2', '456') r.message = 'test' self.assertEqual('test with meta 123 and 456', str(r))