def _test_repex_errors(self, path_object, error, error_type=repex.RepexError): with pytest.raises(error_type) as ex: repex.handle_path(path_object) assert repex.ERRORS[error] in str(ex)
def test_file_no_permissions_to_write_to_file(self): path_object = { 'path': MOCK_TEST_FILE, 'match': '3.1.0-m2', 'replace': '3.1.0-m2', 'with': '3.1.0-m3', 'to_file': '/mock.test' } with pytest.raises(IOError) as ex: repex.handle_path(path_object) assert 'Permission denied' in str(ex)
def test_file_no_permissions_to_write_to_file(self): if os.name == 'nt': self.skipTest('Irrelevant on Windows') pathobj = { 'path': MOCK_TEST_FILE, 'match': '3.1.0-m2', 'replace': '3.1.0-m2', 'with': '3.1.0-m3', 'to_file': '/mock.test' } try: repex.handle_path(pathobj, verbose=True) self.fail() except IOError as ex: self.assertIn('Permission denied', str(ex))
def _test_path_with_and_without_base_directory(self): p = { 'path': os.path.join('single', TEST_FILE_NAME), 'base_directory': TEST_RESOURCES_DIR, 'match': '3.1.0-m2', 'replace': '3.1.0-m2', 'with': '3.1.0-m3', } t = { 'path': MOCK_TEST_FILE, 'match': '3.1.0-m3', 'replace': '3.1.0-m3', 'with': '3.1.0-m2', } repex.handle_path(p, verbose=True) with open(p['path']) as f: content = f.read() self.assertIn('3.1.0-m3', content) repex.handle_path(t, verbose=True) with open(t['path']) as f: content = f.read() self.assertIn('3.1.0-m2', content)
def _test_path_with_and_without_base_directory(self): p = { 'path': os.path.join('single', TEST_FILE_NAME), 'base_directory': TEST_RESOURCES_DIR, 'match': '3.1.0-m2', 'replace': '3.1.0-m2', 'with': '3.1.0-m3', } t = { 'path': MOCK_TEST_FILE, 'match': '3.1.0-m3', 'replace': '3.1.0-m3', 'with': '3.1.0-m2', } repex.handle_path(p) with open(p['path']) as f: content = f.read() assert '3.1.0-m2' not in content assert '3.1.0-m3' in content repex.handle_path(t) with open(t['path']) as f: content = f.read() assert '3.1.0-m2' in content assert '3.1.0-m3' not in content