Skip to content

Commit

Permalink
Restore previous test behviour
Browse files Browse the repository at this point in the history
  • Loading branch information
kunitoki committed Feb 6, 2024
1 parent 4959026 commit 4b65244
Show file tree
Hide file tree
Showing 3 changed files with 188 additions and 8 deletions.
5 changes: 3 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@ before-build = [
"yum localinstall -y lcov-2.0-1.noarch.rpm"
]
test-command = [
"""xvfb-run -a -s \"-screen 0 1024x768x24\" pytest -s {project}/tests || \
{ (mkdir -p /output/compare_data && cp -R {project}/tests/compare_data/* /output/compare_data/) ; exit 1 ; }"""
"xvfb-run -a -s \"-screen 0 1024x768x24\" pytest -s {project}/tests"
# """xvfb-run -a -s \"-screen 0 1024x768x24\" pytest -s {project}/tests || \
# { (mkdir -p /output/compare_data && cp {project}/tests/compare_data/* /output/compare_data/) ; exit 1 ; }"""
]
#repair-wheel-command = """
#pip install auditwheel-symbols && (auditwheel repair -w {dest_dir} {wheel} || auditwheel-symbols --manylinux 2014 {wheel})
Expand Down
179 changes: 179 additions & 0 deletions tests/test_juce_graphics/test_ColourGradient.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,179 @@
import pytest

import popsicle as juce

#==================================================================================================

def test_construct_default():
c = juce.ColourGradient()
assert c.getNumColours() == 0
assert c.isOpaque()
assert c.isRadial == False
assert c.point1 == juce.Point[float](0, 0)
assert c.point2 == juce.Point[float](0, 0)

#==================================================================================================

def test_copy_construct():
c1 = juce.ColourGradient(juce.Colours.black, 0.0, 0.0, juce.Colours.white, 1.0, 1.0, False)
c2 = juce.ColourGradient(c1)
assert c1 == c2
assert not (c1 != c2)

#==================================================================================================

def test_construct_coordinates_linear():
c = juce.ColourGradient(juce.Colours.black, 0.0, 0.0, juce.Colours.white, 1.0, 1.0, False)
assert c.isRadial == False
assert c.point1 == juce.Point[float](0, 0)
assert c.point2 == juce.Point[float](1, 1)
assert c.getNumColours() == 2
assert c.getColour(0) == juce.Colours.black
assert c.getColour(1) == juce.Colours.white

def test_construct_points_linear():
c = juce.ColourGradient(juce.Colours.black, juce.Point[float](0.0, 0.0), juce.Colours.white, juce.Point[float](1.0, 1.0), False)
assert c.isRadial == False
assert c.getNumColours() == 2
assert c.getColour(0) == juce.Colours.black
assert c.getColour(1) == juce.Colours.white

#==================================================================================================

def test_construct_coordinates_radial():
c = juce.ColourGradient(juce.Colours.black, 0.0, 0.0, juce.Colours.white, 1.0, 1.0, True)
assert c.isRadial == True
assert c.point1 == juce.Point[float](0, 0)
assert c.point2 == juce.Point[float](1, 1)
assert c.getNumColours() == 2
assert c.getColour(0) == juce.Colours.black
assert c.getColour(1) == juce.Colours.white

def test_construct_points_radial():
c = juce.ColourGradient(juce.Colours.black, juce.Point[float](0.0, 0.0), juce.Colours.white, juce.Point[float](1.0, 1.0), True)
assert c.isRadial == True
assert c.getNumColours() == 2
assert c.getColour(0) == juce.Colours.black
assert c.getColour(1) == juce.Colours.white

#==================================================================================================

def test_colour_at_position():
c = juce.ColourGradient(juce.Colours.black, 0.0, 0.0, juce.Colours.white, 1.0, 1.0, False)
assert c.getColourAtPosition(0.0) == juce.Colours.black
assert c.getColourAtPosition(0.5) == juce.Colour(127, 127, 127)
assert c.getColourAtPosition(1.0) == juce.Colours.white

#==================================================================================================

def test_get_colour_position():
c = juce.ColourGradient(juce.Colours.black, 0.0, 0.0, juce.Colours.white, 1.0, 1.0, False)
assert c.getColourPosition(0) == pytest.approx(0.0)
assert c.getColourPosition(1) == pytest.approx(1.0)

#==================================================================================================

def test_set_colour():
c = juce.ColourGradient(juce.Colours.black, 0.0, 0.0, juce.Colours.white, 1.0, 1.0, False)
c.setColour(0, juce.Colours.red)
c.setColour(1, juce.Colours.green)
assert c.getColour(0) == juce.Colours.red
assert c.getColour(1) == juce.Colours.green

#==================================================================================================

def test_add_remove_colour():
c = juce.ColourGradient()
assert c.getNumColours() == 0

c.addColour(0.0, juce.Colours.yellow)
assert c.getNumColours() == 1
assert c.getColour(0) == juce.Colours.yellow

c.addColour(0.5, juce.Colours.green)
assert c.getNumColours() == 2
assert c.getColour(0) == juce.Colours.yellow
assert c.getColour(1) == juce.Colours.green

c.addColour(1.0, juce.Colours.red)
assert c.getNumColours() == 3
assert c.getColour(0) == juce.Colours.yellow
assert c.getColour(1) == juce.Colours.green
assert c.getColour(2) == juce.Colours.red

c.removeColour(1)
assert c.getNumColours() == 2
assert c.getColour(0) == juce.Colours.yellow
assert c.getColour(1) == juce.Colours.red

c.clearColours()
assert c.getNumColours() == 0

#==================================================================================================

@pytest.mark.skip(reason="JUCE bug, assert raises when removing index 0")
def test_remove_colour():
c = juce.ColourGradient()
assert c.getNumColours() == 0

c.addColour(0.0, juce.Colours.yellow)
assert c.getNumColours() == 1
assert c.getColour(0) == juce.Colours.yellow

c.removeColour(0)
assert c.getNumColours() == 0

#==================================================================================================

def test_vertical_values():
c = juce.ColourGradient.vertical(juce.Colours.black, 0.0, juce.Colours.white, 1.0)
assert c.getNumColours() == 2
assert c.getColour(0) == juce.Colours.black
assert c.getColour(1) == juce.Colours.white

def test_vertical_rectangle_int():
c = juce.ColourGradient.vertical(juce.Colours.black, juce.Colours.white, juce.Rectangle[int](0, 0, 100, 100))
assert c.getNumColours() == 2
assert c.getColour(0) == juce.Colours.black
assert c.getColour(1) == juce.Colours.white

def test_vertical_rectangle_float():
c = juce.ColourGradient.vertical(juce.Colours.black, juce.Colours.white, juce.Rectangle[float](0, 0, 100, 100))
assert c.getNumColours() == 2
assert c.getColour(0) == juce.Colours.black
assert c.getColour(1) == juce.Colours.white

#==================================================================================================

def test_horizontal_values():
c = juce.ColourGradient.horizontal(juce.Colours.black, 0.0, juce.Colours.white, 1.0)
assert c.getNumColours() == 2
assert c.getColour(0) == juce.Colours.black
assert c.getColour(1) == juce.Colours.white

def test_horizontal_rectangle_int():
c = juce.ColourGradient.horizontal(juce.Colours.black, juce.Colours.white, juce.Rectangle[int](0, 0, 100, 100))
assert c.getNumColours() == 2
assert c.getColour(0) == juce.Colours.black
assert c.getColour(1) == juce.Colours.white

def test_horizontal_rectangle_float():
c = juce.ColourGradient.horizontal(juce.Colours.black, juce.Colours.white, juce.Rectangle[float](0, 0, 100, 100))
assert c.getNumColours() == 2
assert c.getColour(0) == juce.Colours.black
assert c.getColour(1) == juce.Colours.white

#==================================================================================================

def test_is_invisible_is_opaque():
c = juce.ColourGradient(juce.Colours.black, 0.0, 0.0, juce.Colours.white, 1.0, 1.0, False)
assert not c.isInvisible()
assert c.isOpaque()

c = juce.ColourGradient(juce.Colours.transparentBlack, 0.0, 0.0, juce.Colours.white, 1.0, 1.0, False)
assert not c.isInvisible()
assert not c.isOpaque()

c = juce.ColourGradient(juce.Colours.transparentBlack, 0.0, 0.0, juce.Colours.transparentWhite, 1.0, 1.0, False)
assert c.isInvisible()
assert not c.isOpaque()
12 changes: 6 additions & 6 deletions tests/test_juce_graphics/test_Graphics.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def test_fill_all(update_rendering):

assert is_image_equal_reference(update_rendering, image)

#@pytest.mark.skipif(sys.platform != "darwin", reason="Png format loads differently in each platform")
@pytest.mark.skipif(sys.platform != "darwin", reason="Png format loads differently in each platform")
def test_fill_all_image(update_rendering):
image = juce.Image(juce.Image.ARGB, width, height, True)
llsr = juce.LowLevelGraphicsSoftwareRenderer(image)
Expand All @@ -39,7 +39,7 @@ def test_fill_all_image(update_rendering):
g.setTiledImageFill(get_logo_image(), 0, 0, 1.0)
g.fillAll()

assert is_image_equal_reference(update_rendering, image, threshold=1e-8)
assert is_image_equal_reference(update_rendering, image)

#==================================================================================================

Expand Down Expand Up @@ -118,7 +118,7 @@ def test_fill_rect_gradient_horizontal_area(update_rendering):

#==================================================================================================

#@pytest.mark.skipif(sys.platform != "darwin", reason="Png format loads differently in each platform")
@pytest.mark.skipif(sys.platform != "darwin", reason="Png format loads differently in each platform")
def test_fill_rect_image(update_rendering):
image = juce.Image(juce.Image.ARGB, width, height, True)
llsr = juce.LowLevelGraphicsSoftwareRenderer(image)
Expand All @@ -128,9 +128,9 @@ def test_fill_rect_image(update_rendering):
g.setTiledImageFill(get_logo_image(), 50, 50, 1.0)
g.fillRect(rect.getX(), rect.getY(), rect.getWidth(), rect.getHeight())

assert is_image_equal_reference(update_rendering, image, threshold=1e-8)
assert is_image_equal_reference(update_rendering, image)

#@pytest.mark.skipif(sys.platform != "darwin", reason="Png format loads differently in each platform")
@pytest.mark.skipif(sys.platform != "darwin", reason="Png format loads differently in each platform")
def test_fill_rect_image_area(update_rendering):
image = juce.Image(juce.Image.ARGB, width, height, True)
llsr = juce.LowLevelGraphicsSoftwareRenderer(image)
Expand All @@ -139,7 +139,7 @@ def test_fill_rect_image_area(update_rendering):
g.setTiledImageFill(get_logo_image(), 50, 50, 1.0)
g.fillRect(image.getBounds().reduced(100))

assert is_image_equal_reference(update_rendering, image, threshold=1e-8)
assert is_image_equal_reference(update_rendering, image)

#==================================================================================================

Expand Down

0 comments on commit 4b65244

Please sign in to comment.