def test_m_named_args(self): c = TestMethodSelector.HasMethods() fred_selector = m_('sheila', arg2=45, arg1=33) self.assertEqual(fred_selector(c), 134)
def test_m_negative(self): c = TestMethodSelector.HasMethods() foo_selector = m_('foo') self.assertRaises(AttributeError, lambda: foo_selector(c))
def test_m_positional_args(self): c = TestMethodSelector.HasMethods() fred_selector = m_('fred', 45) self.assertEqual(fred_selector(c), 100)
def test_m_result_is_callable(self): foo_selector = m_('foo') self.assertTrue(is_callable(foo_selector))
def test_m_positive(self): c = TestMethodSelector.HasMethods() jim_selector = m_('jim') self.assertEqual(jim_selector(c), 23)
def test_m_named_args(self): c = TestMethodSelector.HasMethods() fred_selector = m_('sheila', arg2 = 45, arg1 = 33) self.assertEqual(fred_selector(c), 134)
return x.first() def count(x): return lambda x: x.count() def order_grouping_by(selector: Callable, type: Order = Order.Asc): """ subselect the group items within each grouping. """ asc = lambda x: x.order_by(lambda y: query(y).select(selector).sum()) desc = lambda x: x.order_by_descending(lambda y: query(y).select(selector). sum()) return asc if type == Order.Asc else desc order_by_duration = order_by(get_sum(a_('duration'))) group_by_category = group_by(a_('parent_category')) group_by_concept = group_by(a_('data.concept_name')) group_by_collection = group_by(a_('data.collection_name')) group_by_date = group_by(m_('date')) group_by_learning_mode = group_by(a_('data.learning_mode')) group_by_element_type = group_by(a_('data.element_type')) group_by_edited = group_by(m_('was_edited')) #order_by_deletion_number = order_by(lambda x: text_deletions(x.data.element_content).count()) #order_by_insertion_number = order_by(lambda x: text_insertions(x.data.element_content).count()) #order_by_deletion_length = order_by(lambda x: text_insertions(x.data.element_content).sum()) #order_by_insertion_length = order_by(lambda x: sum(len(tup[1]) for tup in text_insertions(x.data.element_content)))
def where_unchanged_contains(q: Queryable, string: str): return apply([where(m_('unchanged_contains', string))], q)
def where_inserted_contains(q: Queryable, strings: List[str]): return apply([where(m_('inserted_contains', strings))], q)
def where_deleted_contains(q: Queryable, string: str): return apply([where(m_('deleted_contains', string))], q)