def test_get_glslparsertest_gles2(version, has_bin, forced, tmpdir, mocker): """Tests for assigning the correct binary for GLES tests. Tests with and without the gles binary and with and without the force desktop mode. """ if not has_bin or forced: expected = 'glslparsertest' else: expected = 'glslparsertest_gles2' mocker.patch('framework.test.glsl_parser_test._HAS_GLES_BIN', has_bin) mocker.patch('framework.test.glsl_parser_test._FORCE_DESKTOP_VERSION', forced) p = tmpdir.join('test.frag') p.write(textwrap.dedent("""\ /* [config] * expect_result: pass * glsl_version: {} * [end config] */""".format(version))) inst = glsl.GLSLParserTest(six.text_type(p)) assert os.path.basename(inst.command[0]) == expected
def test_no_config_end(tmpdir): """test.glsl_parser_test.GLSLParserTest: exception is raised if [end config] section is missing.""" p = tmpdir.join('test.frag') p.write('// [config]') with pytest.raises(exceptions.PiglitFatalError): glsl.GLSLParserTest(six.text_type(p))
def test_config_to_command(config, expected, tmpdir): """Test that config blocks are converted into the expected commands.""" p = tmpdir.join('test.frag') p.write(config) test = glsl.GLSLParserTest(six.text_type(p)) # add the filename, which isn't known util now expected.insert(1, six.text_type(p)) assert test.command == expected
def test_bad_section_name(): """test.glsl_parser_test.GLSLParserTest: A section name not in the _CONFIG_KEYS name raises an error""" content = ('// [config]\n' '// expect_result: pass\n' '// glsl_version: 1.10\n' '// new_awesome_key: foo\n' '// [end config]\n') with utils.tempfile(content) as tfile: glsl.GLSLParserTest(tfile)
def test_no_glsl_version(tmpdir): """test.glsl_parser_test.GLSLParserTest: exception is raised if "glsl_version" key is missing.""" p = tmpdir.join('test.frag') p.write(textwrap.dedent("""\ // [config] // expect_result: pass // [end config]""")) with pytest.raises(exceptions.PiglitFatalError): glsl.GLSLParserTest(six.text_type(p))
def test_find_config_start(tmpdir): """test.glsl_parser_test.GLSLParserTest: successfully finds [config] section.""" p = tmpdir.join('test.frag') p.write(textwrap.dedent(""" // [config] // expect_result: pass // glsl_version: 1.10""")) with pytest.raises(exceptions.PiglitFatalError): glsl.GLSLParserTest(six.text_type(p))
def test_no_config_start(tmpdir): """test.glsl_parser_test.GLSLParserTest: exception is raised if [config] section is missing.""" p = tmpdir.join('test.frag') p.write(textwrap.dedent(""" // expect_result: pass // glsl_version: 1.10 // [end config]""")) with pytest.raises(glsl.GLSLParserNoConfigError): glsl.GLSLParserTest(six.text_type(p))
def test_glslparser_initializer(): """test.glsl_parser_test.GLSLParserTest: clas initializes correctly""" content = textwrap.dedent("""\ /* * [config] * expect_result: pass * glsl_version: 1.10 * [end config] */ """) with utils.tempfile(content) as f: glsl.GLSLParserTest(f)
def test_cpp_comments(tmpdir): """test.glsl_parser_test.GLSLParserTest: parses C++ style comments ('//'). """ p = tmpdir.join('test.frag') p.write(textwrap.dedent("""\ // [config] // expect_result: pass // glsl_version: 1.10 // [end config]""")) test = glsl.GLSLParserTest(six.text_type(p)) assert test.command == [os.path.join(_TEST_BIN_DIR, 'glslparsertest'), six.text_type(p), 'pass', '1.10']
def test_bad_section_name(tmpdir): """test.glsl_parser_test.GLSLParserTest: Unknown config keys cause an error.""" p = tmpdir.join('test.frag') p.write(textwrap.dedent("""\ // [config] // expect_result: pass // glsl_version: 1.10 // new_awesome_key: foo // [end config]""")) with pytest.raises(exceptions.PiglitFatalError): glsl.GLSLParserTest(six.text_type(p))
def test_no_config_start(): """test.glsl_parser_test.GLSLParserTest: exception is raised if [config] section is missing """ content = ('// expect_result: pass\n' '// glsl_version: 1.10\n' '// [end config]\n') with utils.tempfile(content) as tfile: with nt.assert_raises(glsl.GLSLParserNoConfigError) as exc: glsl.GLSLParserTest(tfile) nt.assert_equal( exc.exception, 'No [config] section found!', msg="No config section was found and no exception raised")
def test_duplicate_entry(extra, tmpdir): """Test that duplicate entries are an error.""" p = tmpdir.join('test.vert') p.write(textwrap.dedent("""\ // [config] // expect_result: pass // glsl_version: 1.10 // require_extensions: ARB_foobar // check_link: True // {} // [end config]""".format(extra))) with pytest.raises(exceptions.PiglitFatalError): glsl.GLSLParserTest(six.text_type(p))
def test_invalid_extensions_separator(separator, tmpdir): """Test that invalid extension separators are rejected.""" p = tmpdir.join('test.vert') p.write(textwrap.dedent("""\ // [config] // expect_result: pass // glsl_version: 1.10 // require_extensions: ARB_foobar // check_link: True // require_extensions: {} // [end config]""".format(separator))) with pytest.raises(exceptions.PiglitFatalError): glsl.GLSLParserTest(six.text_type(p))
def test_valid_extensions(ext, tmpdir): """Test that invalid extension separators are rejected.""" p = tmpdir.join('test.vert') p.write(textwrap.dedent("""\ // [config] // expect_result: pass // glsl_version: 1.10 // require_extensions: {} // [end config]""".format(ext))) expected = ext.split(' ') test = glsl.GLSLParserTest(six.text_type(p)) assert test.command[-len(expected):] == expected
def test_binary_skip(): """test.glsl_parser_test.GLSLParserTest.is_skip: skips OpenGL tests when not built with desktop support""" content = textwrap.dedent("""\ /* * [config] * expect_result: pass * glsl_version: 1.10 * [end config] */ """) with utils.tempfile(content) as f: test = glsl.GLSLParserTest(f) test.is_skip()
def test_set_glsl_es_version(): """test.glsl_parser_test.GLSLParserTest: sets glsl_es_version""" rt = {'glsl_version': '3.00 es'} with mock.patch.object(glsl.GLSLParserTest, '_GLSLParserTest__parser', mock.Mock(return_value=rt)): with mock.patch.object(glsl.GLSLParserTest, '_GLSLParserTest__get_command', return_value=['foo']): with mock.patch('framework.test.glsl_parser_test.open', mock.mock_open(), create=True): with mock.patch('framework.test.glsl_parser_test.os.stat', mock.mock_open()): test = glsl.GLSLParserTest('foo') nt.eq_(test.glsl_es_version, 3.0)
def test_set_gl_required(): """test.glsl_parser_test.GLSLParserTest: sets gl_required""" rt = {'require_extensions': 'GL_ARB_foobar GL_EXT_foobar'} with mock.patch.object(glsl.GLSLParserTest, '_GLSLParserTest__parser', mock.Mock(return_value=rt)): with mock.patch.object(glsl.GLSLParserTest, '_GLSLParserTest__get_command', return_value=['foo']): with mock.patch('framework.test.glsl_parser_test.open', mock.mock_open(), create=True): with mock.patch('framework.test.glsl_parser_test.os.stat', mock.mock_open()): test = glsl.GLSLParserTest('foo') nt.eq_(test.gl_required, set(['GL_ARB_foobar', 'GL_EXT_foobar']))
def test_empty_in_config_c(tmpdir): """test.glsl_parser_test.GLSLParserTest: C style comments can have blank commented lines.""" p = tmpdir.join('test.frag') p.write(textwrap.dedent("""\ /* [config] * * expect_result: pass * glsl_version: 1.10 * [end config] */""")) test = glsl.GLSLParserTest(six.text_type(p)) assert test.command == [os.path.join(_TEST_BIN_DIR, 'glslparsertest'), six.text_type(p), 'pass', '1.10']
def test_skip_desktop_without_binary(tmpdir, mocker): """There is no way to run desktop tests with only GLES compiled make sure we don't try. """ mocker.patch('framework.test.glsl_parser_test._HAS_GL_BIN', False) p = tmpdir.join('test.frag') p.write(textwrap.dedent("""\ /* [config] * expect_result: pass * glsl_version: 1.10 * [end config] */""")) test = glsl.GLSLParserTest(six.text_type(p)) with pytest.raises(_TestIsSkip): test.is_skip()
def test_add_compatibility_requirement_fastskip(version, extension, tmpdir, mocker): """When running GLES tests using the GL binary ensure that the proper ARB_ES<ver> compatibility extension is added to the requirements. This test checks the fast skipping variable """ mocker.patch('framework.test.glsl_parser_test._HAS_GLES_BIN', False) p = tmpdir.join('test.frag') p.write(textwrap.dedent("""\ /* [config] * expect_result: pass * glsl_version: {} * require_extensions: GL_ARB_ham_sandwhich * [end config] */""".format(version))) test = glsl.GLSLParserTest(six.text_type(p)) # The arb_compat extension was added to the fast skipping arguments assert extension in test.gl_required
def check_bad_character(tfile): """ Check for bad characters """ glsl.GLSLParserTest(tfile)
def test_exclude_not_added_to_gl_required(self, tmpdir): p = tmpdir.join('test.frag') self.write_config(p, extra="require_extensions: GL_ARB_foo !GL_ARB_bar") assert glsl.GLSLParserTest(six.text_type(p)).gl_required == \ {'GL_ARB_foo'}
def test(ver, expected): with utils.tempfile(content.format(ver)) as f: test = glsl.GLSLParserTest(f) nt.assert_in(expected, test.gl_required)
def test_glsl_es_version(self, tmpdir): p = tmpdir.join('test.frag') self.write_config(p, version='3.0') assert glsl.GLSLParserTest(six.text_type(p)).glsl_es_version == 3.0
def check_no_duplicates(content): """ Ensure that duplicate entries raise an error """ with utils.tempfile(content) as tfile: glsl.GLSLParserTest(tfile)
def _check_config(content): """ This is the test that actually checks the glsl config section """ with utils.tempfile(content) as tfile: return glsl.GLSLParserTest(tfile), tfile
def test_find_config_start(): """test.glsl_parser_test.GLSLParserTest: successfully finds [config] section """ content = ('// [config]\n' '// glsl_version: 1.10\n' '//\n') with utils.tempfile(content) as tfile: glsl.GLSLParserTest(tfile)
def check_good_extension(file_): """ A good extension should not raise a GLSLParserException """ glsl.GLSLParserTest(file_)
def test_no_glsl_version(): """test.glsl_parser_test.GLSLParserTest: exception is raised if "glsl_version" key is missing """ content = ('// [config]\n' '// expect_result: pass\n' '// [end config]\n') with utils.tempfile(content) as tfile: glsl.GLSLParserTest(tfile)
def test(content, expected): with utils.tempfile(content) as f: t = glsl.GLSLParserTest(f) nt.eq_(os.path.basename(t.command[0]), expected)