def test_optimize_distinct(self): """ Unoptimized: Select._select({'col1': ['values']}, col2='xyz').distinct() Optimized: Select._select_distinct({'col1': ['values']}, col2='xyz') """ unoptimized = ( (getattr, (RESULT_TOKEN, '_select'), {}), (RESULT_TOKEN, ({'col1': ['values']},), {'col2': 'xyz'}), (_sqlite_distinct, (RESULT_TOKEN,), {}), ) optimized = Query._optimize(unoptimized) expected = ( (getattr, (RESULT_TOKEN, '_select_distinct'), {}), (RESULT_TOKEN, ({'col1': ['values']},), {'col2': 'xyz'}), ) self.assertEqual(optimized, expected)
def test_optimize_aggregation(self): """ Unoptimized: Select._select({'col1': ['values']}, col2='xyz').sum() Optimized: Select._select_aggregate('SUM', {'col1': ['values']}, col2='xyz') """ unoptimized = ( (getattr, (RESULT_TOKEN, '_select'), {}), (RESULT_TOKEN, ({'col1': ['values']},), {'col2': 'xyz'}), (_apply_to_data, (_sqlite_sum, RESULT_TOKEN,), {}), ) optimized = Query._optimize(unoptimized) expected = ( (getattr, (RESULT_TOKEN, '_select_aggregate'), {}), (RESULT_TOKEN, ('SUM', {'col1': ['values']},), {'col2': 'xyz'}), ) self.assertEqual(optimized, expected)