TestFlowControl.py 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. from __future__ import absolute_import
  2. from copy import deepcopy
  3. from unittest import TestCase
  4. from Cython.Compiler.FlowControl import (
  5. NameAssignment, StaticAssignment, Argument, NameDeletion)
  6. class FakeType(object):
  7. is_pyobject = True
  8. class FakeNode(object):
  9. pos = ('filename.pyx', 1, 2)
  10. cf_state = None
  11. type = FakeType()
  12. def infer_type(self, scope):
  13. return self.type
  14. class FakeEntry(object):
  15. type = FakeType()
  16. class TestGraph(TestCase):
  17. def test_deepcopy(self):
  18. lhs, rhs = FakeNode(), FakeNode()
  19. entry = FakeEntry()
  20. entry.pos = lhs.pos
  21. name_ass = NameAssignment(lhs, rhs, entry)
  22. ass = deepcopy(name_ass)
  23. self.assertTrue(ass.lhs)
  24. self.assertTrue(ass.rhs)
  25. self.assertTrue(ass.entry)
  26. self.assertEqual(ass.pos, name_ass.pos)
  27. self.assertFalse(ass.is_arg)
  28. self.assertFalse(ass.is_deletion)
  29. static_ass = StaticAssignment(entry)
  30. ass = deepcopy(static_ass)
  31. self.assertTrue(ass.lhs)
  32. self.assertTrue(ass.rhs)
  33. self.assertTrue(ass.entry)
  34. self.assertEqual(ass.pos, static_ass.pos)
  35. self.assertFalse(ass.is_arg)
  36. self.assertFalse(ass.is_deletion)
  37. arg_ass = Argument(lhs, rhs, entry)
  38. ass = deepcopy(arg_ass)
  39. self.assertTrue(ass.lhs)
  40. self.assertTrue(ass.rhs)
  41. self.assertTrue(ass.entry)
  42. self.assertEqual(ass.pos, arg_ass.pos)
  43. self.assertTrue(ass.is_arg)
  44. self.assertFalse(ass.is_deletion)
  45. name_del = NameDeletion(lhs, entry)
  46. ass = deepcopy(name_del)
  47. self.assertTrue(ass.lhs)
  48. self.assertTrue(ass.rhs)
  49. self.assertTrue(ass.entry)
  50. self.assertEqual(ass.pos, name_del.pos)
  51. self.assertFalse(ass.is_arg)
  52. self.assertTrue(ass.is_deletion)