| 30 | |
| 31 | |
| 32 | class TestBase(unittest.TestCase): |
| 33 | |
| 34 | def setUp(self, prefix_for_tmp_repo): |
| 35 | """Creates temporary dir and cds to it.""" |
| 36 | logging.basicConfig(stream=sys.stdout, level=logging.INFO) |
| 37 | self.path = tempfile.mkdtemp(prefix=prefix_for_tmp_repo) |
| 38 | logging.debug('Created temporary directory {0}'.format(self.path)) |
| 39 | os.chdir(self.path) |
| 40 | |
| 41 | def tearDown(self): |
| 42 | """Removes the temporary dir.""" |
| 43 | rmtree(self.path) |
| 44 | |
| 45 | # Python 2/3 compatibility |
| 46 | def assertItemsEqual(self, actual, expected, msg=None): |
| 47 | try: |
| 48 | return super(TestBase, self).assertItemsEqual(actual, expected, msg=msg) |
| 49 | except AttributeError: |
| 50 | try: |
| 51 | # Checks that actual and expected have the same elements in the same |
| 52 | # number, regardless of their order |
| 53 | return super(TestBase, self).assertCountEqual(actual, expected, msg=msg) |
| 54 | except AttributeError: |
| 55 | return self.assertEqual(sorted(actual), sorted(expected), msg=msg) |
| 56 | |
| 57 | def assertRaisesRegexp(self, exc, r, fun, *args, **kwargs): |
| 58 | try: |
| 59 | fun(*args, **kwargs) |
| 60 | self.fail('Exception not raised') |
| 61 | except exc as e: |
| 62 | msg = stderr(e) if isinstance(e, ErrorReturnCode) else str(e) |
| 63 | if not re.search(r, msg): |
| 64 | self.fail('No "{0}" found in "{1}"'.format(r, msg)) |
| 65 | |
| 66 | |
| 67 | def rmtree(path): |
nothing calls this directly
no outgoing calls
no test coverage detected