def test_additions_and_removals(self): c = SetUpdateClause('s', set((2, 3)), previous=set((1, 2))) c._analyze() c.set_context_id(0) self.assertIsNone(c._assignments) self.assertEqual(c._additions, set((3, ))) self.assertEqual(c._removals, set((1, ))) self.assertEqual(c.get_context_size(), 2) self.assertEqual(str(c), '"s" = "s" + %(0)s, "s" = "s" - %(1)s') ctx = {} c.update_context(ctx) self.assertEqual(ctx, {'0': set((3, )), '1': set((1, ))})
def test_update_from_none(self): c = SetUpdateClause('s', set((1, 2)), previous=None) c._analyze() c.set_context_id(0) self.assertEqual(c._assignments, set((1, 2))) self.assertIsNone(c._additions) self.assertIsNone(c._removals) self.assertEqual(c.get_context_size(), 1) self.assertEqual(str(c), '"s" = %(0)s') ctx = {} c.update_context(ctx) self.assertEqual(ctx, {'0': set((1, 2))})
def test_no_update(self): """ tests an unchanged value creates an empty update statement """ c = SetUpdateClause('s', set((1, 2)), previous=set((1, 2))) c._analyze() c.set_context_id(0) self.assertIsNone(c._assignments) self.assertIsNone(c._additions) self.assertIsNone(c._removals) self.assertEqual(c.get_context_size(), 0) self.assertEqual(str(c), '') ctx = {} c.update_context(ctx) self.assertEqual(ctx, {})
def test_null_update(self): """ tests setting a set to None creates an empty update statement """ c = SetUpdateClause("s", None, previous=set((1, 2))) c._analyze() c.set_context_id(0) self.assertIsNone(c._assignments) self.assertIsNone(c._additions) self.assertIsNone(c._removals) self.assertEqual(c.get_context_size(), 0) self.assertEqual(str(c), "") ctx = {} c.update_context(ctx) self.assertEqual(ctx, {})
def test_update_empty_set(self): """tests assigning a set to an empty set creates a nonempty update statement and nonzero context size.""" c = SetUpdateClause(field='s', value=set()) c._analyze() c.set_context_id(0) self.assertEqual(c._assignments, set()) self.assertIsNone(c._additions) self.assertIsNone(c._removals) self.assertEqual(c.get_context_size(), 1) self.assertEqual(str(c), '"s" = %(0)s') ctx = {} c.update_context(ctx) self.assertEqual(ctx, {'0': set()})