Exemple #1
0
    def test_basic(self):
        md = {}
        with self.assertRaises(ModelError):
            measure = Measure.from_metadata(md)

        measure = Measure.from_metadata("amount")
        self.assertIsInstance(measure, Measure)
        self.assertEqual("amount", measure.name)

        md = {"name": "amount"}
        measure = Measure.from_metadata(md)
        self.assertEqual("amount", measure.name)
Exemple #2
0
    def test_create_default_aggregates(self):
        measure = Measure.from_metadata("amount")
        aggs = measure.default_aggregates()
        self.assertEqual(1, len(aggs))
        agg = aggs[0]
        self.assertEqual("amount_sum", agg.name)
        self.assertEqual("amount", agg.measure)
        self.assertEqual("sum", agg.function)
        self.assertIsNone(agg.formula)

        md = {"name": "amount", "aggregates": ["sum", "min"]}
        measure = Measure.from_metadata(md)
        aggs = measure.default_aggregates()
        self.assertEqual(2, len(aggs))
        self.assertEqual("amount_sum", aggs[0].name)
        self.assertEqual("amount", aggs[0].measure)
        self.assertEqual("sum", aggs[0].function)
        self.assertIsNone(aggs[0].formula)

        self.assertEqual("amount_min", aggs[1].name)
        self.assertEqual("amount", aggs[1].measure)
        self.assertEqual("min", aggs[1].function)
        self.assertIsNone(aggs[1].formula)
Exemple #3
0
 def test_copy(self):
     md = {"name": "amount"}
     measure = Measure.from_metadata(md)
     measure2 = copy.deepcopy(measure)
     self.assertEqual(measure, measure2)