<commit_before># -----------------------------------------------------------------------------
# VisPy - Copyright (c) 2013, Vispy Development Team
# All rights reserved.
# -----------------------------------------------------------------------------
import unittest
from vispy import gl

from vispy.oogl.program import Program
from vispy.oogl.shader import VertexShader
from vispy.oogl.shader import FragmentShader
from vispy.oogl.program import ProgramException




# -----------------------------------------------------------------------------
class ProgramTest(unittest.TestCase):

    def test_init(self):
        program = Program()
        assert program._handle == 0
        assert program._need_update == False
        assert program._valid  == False
        assert program.shaders == []

    def test_delete_no_context(self):
        program = Program()
        program.delete()

    def test_init_from_string(self):
        program = Program("A","B")
        assert len(program.shaders) == 2
        assert program.shaders[0].code == "A"
        assert program.shaders[1].code == "B"

    def test_init_from_shader(self):
        program = Program(VertexShader("A"),FragmentShader("B"))
        assert len(program.shaders) == 2
        assert program.shaders[0].code == "A"
        assert program.shaders[1].code == "B"

    def test_unique_shader(self):
        vert = VertexShader("A")
        frag = FragmentShader("B")
        program = Program([vert,vert],[frag,frag,frag])
        assert len(program.shaders) == 2

    def test_uniform(self):
        vert = VertexShader("uniform float A;")
        frag = FragmentShader("uniform float A; uniform vec4 B;")
        program = Program(vert,frag)
        assert program.uniforms[0].name == 'A'
        assert program.uniforms[0].gtype == gl.GL_FLOAT
        assert program.uniforms[1].name == 'B'
        assert program.uniforms[1].gtype == gl.GL_FLOAT_VEC4

    def test_attributes(self):
        vert = VertexShader("attribute float A;")
        frag = FragmentShader("")
        program = Program(vert,frag)
        assert program.attributes[0].name == 'A'
        assert program.attributes[0].gtype == gl.GL_FLOAT
    
    def test_attach(self):
        vert = VertexShader("A")
        frag = FragmentShader("B")
        program = Program(vert)
        program.attach(frag)
        assert len(program.shaders) == 2
        assert program.shaders[0].code == "A"
        assert program.shaders[1].code == "B"

    def test_detach(self):
        vert = VertexShader("A")
        frag = FragmentShader("B")
        program = Program(vert, frag)
        program.detach(frag)
        assert len(program.shaders) == 1
        assert program.shaders[0].code == "A"

    def test_failed_build(self):
        vert = VertexShader("A")
        frag = FragmentShader("B")

        program = Program(vert = vert)
        with self.assertRaises(RuntimeError):
            program.activate()

        program = Program(frag = frag)
        with self.assertRaises(RuntimeError):
            program.activate()

    def test_setitem(self):
        vert = VertexShader("")
        frag = FragmentShader("")

        program = Program(vert,frag)
        with self.assertRaises(NameError):
            program["A"] = 1



if __name__ == "__main__":
    unittest.main()<commit_msg>Added unittests that fail<commit_after># -----------------------------------------------------------------------------
# VisPy - Copyright (c) 2013, Vispy Development Team
# All rights reserved.
# -----------------------------------------------------------------------------
import unittest
import numpy as np

from vispy import gl
from vispy.oogl.program import Program
from vispy.oogl.shader import VertexShader
from vispy.oogl.shader import FragmentShader
from vispy.oogl.program import ProgramException




# -----------------------------------------------------------------------------
class ProgramTest(unittest.TestCase):

    def test_init(self):
        program = Program()
        assert program._handle == 0
        assert program._need_update == False
        assert program._valid  == False
        assert program.shaders == []

    def test_delete_no_context(self):
        program = Program()
        program.delete()

    def test_init_from_string(self):
        program = Program("A","B")
        assert len(program.shaders) == 2
        assert program.shaders[0].code == "A"
        assert program.shaders[1].code == "B"

    def test_init_from_shader(self):
        program = Program(VertexShader("A"),FragmentShader("B"))
        assert len(program.shaders) == 2
        assert program.shaders[0].code == "A"
        assert program.shaders[1].code == "B"

    def test_unique_shader(self):
        vert = VertexShader("A")
        frag = FragmentShader("B")
        program = Program([vert,vert],[frag,frag,frag])
        assert len(program.shaders) == 2

    def test_uniform(self):
        vert = VertexShader("uniform float A;")
        frag = FragmentShader("uniform float A; uniform vec4 B;")
        program = Program(vert,frag)
        assert program.uniforms[0].name == 'A'
        assert program.uniforms[0].gtype == gl.GL_FLOAT
        assert program.uniforms[1].name == 'B'
        assert program.uniforms[1].gtype == gl.GL_FLOAT_VEC4

    def test_attributes(self):
        vert = VertexShader("attribute float A;")
        frag = FragmentShader("")
        program = Program(vert,frag)
        assert program.attributes[0].name == 'A'
        assert program.attributes[0].gtype == gl.GL_FLOAT
    
    def test_attach(self):
        vert = VertexShader("A")
        frag = FragmentShader("B")
        program = Program(vert)
        program.attach(frag)
        assert len(program.shaders) == 2
        assert program.shaders[0].code == "A"
        assert program.shaders[1].code == "B"

    def test_detach(self):
        vert = VertexShader("A")
        frag = FragmentShader("B")
        program = Program(vert, frag)
        program.detach(frag)
        assert len(program.shaders) == 1
        assert program.shaders[0].code == "A"

    def test_failed_build(self):
        vert = VertexShader("A")
        frag = FragmentShader("B")

        program = Program(vert = vert)
        with self.assertRaises(RuntimeError):
            program.activate()

        program = Program(frag = frag)
        with self.assertRaises(RuntimeError):
            program.activate()

    def test_setitem(self):
        vert = VertexShader("")
        frag = FragmentShader("")

        program = Program(vert,frag)
        with self.assertRaises(NameError):
            program["A"] = 1

    def test_set_uniform_vec4(self):
        vert = VertexShader("uniform vec4 color;")
        frag = FragmentShader("")

        program = Program(vert,frag)
        program["color"] = 1,1,1,1

    def test_set_attribute_float(self):

        vert = VertexShader("attribute float f;")
        frag = FragmentShader("")

        program = Program(vert,frag)
        program["f"] = np.array(100, dtype=np.float32)
        assert program._attributes["f"].count == 100

        program = Program(vert,frag)
        program["f"] = np.array((100,1,1), dtype=np.float32)
        assert program._attributes["f"].count == 100


    def test_set_attribute_vec4(self):
        vert = VertexShader("attribute vec4 color;")
        frag = FragmentShader("")

        program = Program(vert,frag)
        with self.assertRaises(ValueError):
            program["color"] = np.array(3, dtype=np.float32)

        program = Program(vert,frag)
        with self.assertRaises(ValueError):
            program["color"] = np.array((100,5), dtype=np.float32)

        program = Program(vert,frag)
        program["color"] = np.array((100,4), dtype=np.float32)
        assert program._attributes["f"].count == 100

        program = Program(vert,frag)
        program["color"] = np.array((100,1,4), dtype=np.float32)
        assert program._attributes["f"].count == 100

        program = Program(vert,frag)
        program["color"] = np.array(100, dtype=(np.float32,4))
        assert program._attributes["f"].count == 100


if __name__ == "__main__":
    unittest.main()
{'fraction_non_alphanumeric': 0.175537109375, 'fraction_numerical': 0.0140380859375, 'mean_word_length': 2.1547939930689255, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5428518', 'n_tokens_mistral': 2365, 'n_tokens_neox': 2240, 'n_words': 494}