Coverage for cogapp/backward.py: 69.23%

Shortcuts on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

22 statements  

1"""Compatibility between Py2 and Py3.""" 

2 

3import sys 

4import unittest 

5 

6PY3 = sys.version_info[0] == 3 

7 

8if PY3: 8 ↛ 14line 8 didn't jump to line 14, because the condition on line 8 was never false

9 string_types = (str,bytes) 

10 bytes_types = (bytes,) 

11 def to_bytes(s): 

12 return s.encode('utf8') 

13else: 

14 string_types = (basestring,) 

15 bytes_types = (str,) 

16 def to_bytes(s): 

17 return s 

18 

19# Pythons 2 and 3 differ on where to get StringIO 

20try: 

21 from cStringIO import StringIO 

22except ImportError: 

23 from io import StringIO 

24 

25 

26def unittest_has(method): 

27 """Does `unittest.TestCase` have `method` defined?""" 

28 return hasattr(unittest.TestCase, method) 

29 

30 

31class TestCase(unittest.TestCase): 

32 """Just like unittest.TestCase, but with assert methods added. 

33 

34 Designed to be compatible with 3.1 unittest. Methods are only defined if 

35 `unittest` doesn't have them. 

36 

37 """ 

38 # pylint: disable=missing-docstring 

39 

40 if not unittest_has('assertRaisesRegex'): 40 ↛ 41line 40 didn't jump to line 41, because the condition on line 40 was never true

41 def assertRaisesRegex(self, *args, **kwargs): 

42 return self.assertRaisesRegexp(*args, **kwargs)