def test_load_snippets_html(self): # Need to be in the fixture directory # so the source path is displayed correctly old_cwd = os.getcwd() self.addCleanup(lambda: os.chdir(old_cwd)) os.chdir(fixture_path('')) src_path = fixture_path('snippet_src.py') self._init_src_file(100, src_path) # One higher-level test to make sure # the snippets are being rendered correctly violations = [10, 12, 13, 50, 51, 54, 55, 57] snippets_html = '\n\n'.join( Snippet.load_snippets_html('snippet_src.py', violations) ) # Load the fixture for the expected contents expected_path = fixture_path('snippet_list.html') with open(expected_path) as fixture_file: expected = fixture_file.read() # Check that we got what we expected assert_long_str_equal(expected, snippets_html, strip=True)
def test_load_snippets_non_ascii(self): # Need to be in the fixture directory # so the source path is displayed correctly old_cwd = os.getcwd() self.addCleanup(lambda: os.chdir(old_cwd)) os.chdir(fixture_path('')) src_path = fixture_path('snippet_src.py') self._init_src_file(100, src_path) # One higher-level test to make sure # the snippets are being rendered correctly violations = [10, 12, 13, 50, 51, 54, 55, 57] snippets_html = '\n\n'.join( Snippet.load_snippets_html('snippet_non_ascii.py', violations) )
def _compare_snippets_html_output(self, filename, violations, expected_out_filename): # Need to be in the fixture directory # so the source path is displayed correctly old_cwd = os.getcwd() self.addCleanup(lambda: os.chdir(old_cwd)) os.chdir(fixture_path("")) # One higher-level test to make sure # the snippets are being rendered correctly snippets_html = "\n\n".join(Snippet.load_snippets_html(filename, violations)) # Load the fixture for the expected contents expected_path = fixture_path(expected_out_filename) with open(expected_path) as fixture_file: expected = fixture_file.read() if isinstance(expected, six.binary_type): expected = expected.decode("utf-8") # Check that we got what we expected assert_long_str_equal(expected, snippets_html, strip=True)
def setUp(self): """ Patch the output of `git diff` and set the cwd to the fixtures dir """ self._mock_popen = patch('subprocess.Popen').start() self._mock_sys = patch('diff_cover.tool.sys').start() # Set the CWD to the fixtures dir self._old_cwd = os.getcwd() os.chdir(fixture_path(''))
def _compare_snippets_html_output(self, filename, violations, expected_out_filename): # Need to be in the fixture directory # so the source path is displayed correctly old_cwd = os.getcwd() self.addCleanup(lambda: os.chdir(old_cwd)) os.chdir(fixture_path('')) # One higher-level test to make sure # the snippets are being rendered correctly snippets_html = '\n\n'.join( Snippet.load_snippets_html(filename, violations) ) # Load the fixture for the expected contents expected_path = fixture_path(expected_out_filename) with open(expected_path) as fixture_file: expected = fixture_file.read() if isinstance(expected, six.binary_type): expected = expected.decode('utf-8') # Check that we got what we expected assert_long_str_equal(expected, snippets_html, strip=True)
def _compare_snippets_output(self, format, filename, violations, expected_out_filename): # Need to be in the fixture directory # so the source path is displayed correctly old_cwd = os.getcwd() self.addCleanup(lambda: os.chdir(old_cwd)) os.chdir(fixture_path("")) # One higher-level test to make sure # the snippets are being rendered correctly formatted_snippets = Snippet.load_formatted_snippets( filename, violations) snippets_selected = "\n\n".join(formatted_snippets[format]) # Load the fixture for the expected contents expected_path = fixture_path(expected_out_filename) with open(expected_path, encoding="utf-8") as fixture_file: expected = fixture_file.read() if isinstance(expected, bytes): expected = expected.decode("utf-8") # Check that we got what we expected assert_long_str_equal(expected, snippets_selected, strip=True)
def setUp(self): """ Patch the output of `git` commands and `os.getcwd` set the cwd to the fixtures dir """ # Set the CWD to the fixtures dir self._old_cwd = os.getcwd() os.chdir(fixture_path('')) self._mock_popen = patch('subprocess.Popen').start() self._mock_sys = patch('diff_cover.tool.sys').start() self._mock_getcwd = patch('diff_cover.tool.os.getcwd').start() self._git_root_path = '/project/path' self._mock_getcwd.return_value = self._git_root_path
def setUp(self): """ Patch the output of `git` commands and `os.getcwd` set the cwd to the fixtures dir """ # Set the CWD to the fixtures dir self._old_cwd = os.getcwd() os.chdir(fixture_path("")) cwd = os.getcwd() self._mock_popen = patch("subprocess.Popen").start() self._mock_sys = patch(f"{self.tool_module}.sys").start() try: self._mock_getcwd = patch(f"{self.tool_module}.os.getcwdu").start() except AttributeError: self._mock_getcwd = patch(f"{self.tool_module}.os.getcwd").start() self._git_root_path = cwd self._mock_getcwd.return_value = self._git_root_path
def setUp(self): """ Patch the output of `git` commands and `os.getcwd` set the cwd to the fixtures dir """ # Set the CWD to the fixtures dir self._old_cwd = os.getcwd() os.chdir(fixture_path("")) cwd = os.getcwd() self._mock_popen = patch("subprocess.Popen").start() self._mock_sys = patch("diff_cover.tool.sys").start() try: self._mock_getcwd = patch("diff_cover.tool.os.getcwdu").start() except AttributeError: self._mock_getcwd = patch("diff_cover.tool.os.getcwd").start() self._git_root_path = cwd self._mock_getcwd.return_value = self._git_root_path