示例#1
0
def _compare_snippets_output(format_, filename, violations,
                             expected_out_filename):
    # 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 expected.strip() == snippets_selected.strip()
示例#2
0
    def setup(self, mocker):
        """
        Patch the output of `git` commands and `os.getcwd`
        set the cwd to the fixtures dir
        """
        # Set the CWD to the fixtures dir
        old_cwd = os.getcwd()
        os.chdir(fixture_path(""))
        cwd = os.getcwd()

        self._mock_popen = mocker.patch("subprocess.Popen")
        self._mock_sys = mocker.patch(f"{self.tool_module}.sys")
        try:
            self._mock_getcwd = mocker.patch(f"{self.tool_module}.os.getcwdu")
        except AttributeError:
            self._mock_getcwd = mocker.patch(f"{self.tool_module}.os.getcwd")
        self._git_root_path = cwd
        self._mock_getcwd.return_value = self._git_root_path

        yield

        os.chdir(old_cwd)
示例#3
0
def switch_to_fixture_dir(request):
    # Need to be in the fixture directory
    # so the source path is displayed correctly
    os.chdir(fixture_path(""))
    yield
    os.chdir(request.config.invocation_dir)
import os

from pytest import fixture, raises

from stencil_lang.interpreter.stencil import apply_stencil
from stencil_lang.structures import Matrix
from stencil_lang.errors import InvalidStencilDimensionsError

from tests.helpers import fixture_path, assert_exc_info_msg, open_matrix


@fixture(params=os.listdir(fixture_path('stencil')))
def matrix_name(request):
    return request.param


class TestApplyStencil(object):
    def test_successful_application(self, matrix_name):
        stencil_matrix = open_matrix('stencil', matrix_name)
        before_matrix = open_matrix('before', matrix_name)
        after_matrix = open_matrix('after', matrix_name)
        computed_matrix = apply_stencil(stencil_matrix, before_matrix)
        assert computed_matrix == after_matrix

    def test_zero_dimension(self):
        with raises(InvalidStencilDimensionsError) as exc_info:
            apply_stencil(Matrix(0, 4, []), Matrix(4, 4, range(16)))
        assert_exc_info_msg(
            exc_info, 'Invalid odd dimensions for stencil: (0, 4)')

    def test_even_dimension(self):
 def test_simple(self, matrix_name):
     assert (from_file(fixture_path(matrix_name)) ==
             Matrix(2, 2, [11.7, 52, -34, -12.2]))