def test_stencil_depth_args(): '''Check that invalid index values for the depth method in an instance of the GOStencil class cause an exception to be raised. ''' stencil = GOStencil() stencil_string = "go_stencil(010,111,010)" parsed_stencil = expr.FORT_EXPRESSION.parseString(stencil_string)[0] stencil.load(parsed_stencil, "kernel_stencil") for i, j in [(-2, 0), (2, 0), (0, -2), (0, 2)]: with pytest.raises(GenerationError) as excinfo: stencil.depth(i, j) assert "must be between -1 and 1 but found ({0},{1})".format(i, j) \ in str(excinfo.value)
def test_stencil_case_1(): '''test that the metadata name 'go_stencil' can be provided in lower, or upper case. ''' stencil = GOStencil() stencil_string = "go_StEnCiL(234,915,876)" parsed_stencil = expr.FORT_EXPRESSION.parseString(stencil_string)[0] stencil.load(parsed_stencil, "kernel_stencil") assert stencil.has_stencil expected = [8, 7, 6, 9, 1, 5, 2, 3, 4] exp_index = 0 for idx2 in range(-1, 2): for idx1 in range(-1, 2): assert stencil.depth(idx1, idx2) == expected[exp_index] exp_index += 1
def test_stencil_case_1(): '''test that the metadata name 'go_stencil' can be provided in lower, or upper case. ''' stencil = GOStencil() stencil_string = "go_StEnCiL(000,011,000)" parsed_stencil = expr.FORT_EXPRESSION.parseString(stencil_string)[0] stencil.load(parsed_stencil, "kernel_stencil") assert stencil.has_stencil for idx2 in range(-1, 2): for idx1 in range(-1, 2): if idx1 in [0, 1] and idx2 == 0: expected_depth = 1 else: expected_depth = 0 assert stencil.depth(idx1, idx2) == expected_depth
def test_not_initialised(): '''A GOStencil object can be created in isolation and then have its stencil information initialised using the load() method. If a GOStencil object's stencil information has not been initialised then asking for stencil information using the has_stencil, name and depth methods should return an exception. This test checks that an exception is raised as expected. ''' stencil = GOStencil() with pytest.raises(GenerationError) as excinfo: _ = stencil.has_stencil assert "ensure the load() method is called" in str(excinfo.value) with pytest.raises(GenerationError) as excinfo: _ = stencil.name assert "ensure the load() method is called" in str(excinfo.value) with pytest.raises(GenerationError) as excinfo: _ = stencil.depth(0, 0) assert "ensure the load() method is called" in str(excinfo.value)