Skip to content

Commit

Permalink
Remove nose.tools dependency.
Browse files Browse the repository at this point in the history
  • Loading branch information
tshead committed Jul 11, 2024
1 parent 9d89797 commit 58473cf
Show file tree
Hide file tree
Showing 23 changed files with 292 additions and 257 deletions.
42 changes: 21 additions & 21 deletions features/steps/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@

import importlib
import io
import nose.tools
import numpy
import os
import xml.etree.ElementTree as xml

import test
import testing

if not os.path.exists(testing.backend_dir):
Expand All @@ -30,22 +30,22 @@ def step_impl(context):
target = os.path.join(testing.backend_dir, "%s.html" % context.name)
context.backend.render(context.canvas, target)
#html = xml.parse(target)
#nose.tools.assert_equal(html.getroot().tag, "{http://www.w3.org/2000/svg}svg")
#test.assert_equal(html.getroot().tag, "{http://www.w3.org/2000/svg}svg")


@then(u'the canvas can be rendered to an html buffer')
def step_impl(context):
buffer = io.BytesIO()
context.backend.render(context.canvas, buffer)
#html = xml.parse(buffer.getvalue())
#nose.tools.assert_equal(html.getroot().tag, "html")
#test.assert_equal(html.getroot().tag, "html")


@then(u'the canvas can be rendered to a returned html dom')
def step_impl(context):
html = context.backend.render(context.canvas)
nose.tools.assert_is_instance(html, xml.Element)
nose.tools.assert_equal(html.tag, "div")
test.assert_is_instance(html, xml.Element)
test.assert_equal(html.tag, "div")


@then(u'the canvas can be rendered to a pdf file')
Expand All @@ -70,8 +70,8 @@ def step_impl(context):
target = os.path.join(testing.backend_dir, "%s.png" % context.name)
context.backend.render(context.canvas, target)
image = testing.read_png(target)
nose.tools.assert_equal(image.shape, (600, 600, 4))
nose.tools.assert_equal(image.dtype, "uint8")
test.assert_equal(image.shape, (600, 600, 4))
test.assert_equal(image.dtype, "uint8")


@then(u'the canvas can be rendered to a png buffer')
Expand All @@ -81,58 +81,58 @@ def step_impl(context):
buffer.seek(0)

image = testing.read_png(buffer)
nose.tools.assert_equal(image.shape, (600, 600, 4))
nose.tools.assert_equal(image.dtype, "uint8")
test.assert_equal(image.shape, (600, 600, 4))
test.assert_equal(image.dtype, "uint8")


@then(u'the canvas can be rendered to a returned png document')
def step_impl(context):
png = context.backend.render(context.canvas)
image = testing.read_png(io.BytesIO(png))
nose.tools.assert_equal(image.shape, (600, 600, 4))
nose.tools.assert_equal(image.dtype, "uint8")
test.assert_equal(image.shape, (600, 600, 4))
test.assert_equal(image.dtype, "uint8")


@then(u'the canvas can be rendered to a 200 pixel wide png document')
def step_impl(context):
png = context.backend.render(context.canvas, width="200px")
image = testing.read_png(io.BytesIO(png))
nose.tools.assert_equal(image.shape, (200, 200, 4))
nose.tools.assert_equal(image.dtype, "uint8")
test.assert_equal(image.shape, (200, 200, 4))
test.assert_equal(image.dtype, "uint8")

@then(u'the canvas can be rendered to a 150 pixel high png document')
def step_impl(context):
png = context.backend.render(context.canvas, height="150px")
image = testing.read_png(io.BytesIO(png))
nose.tools.assert_equal(image.shape, (150, 150, 4))
nose.tools.assert_equal(image.dtype, "uint8")
test.assert_equal(image.shape, (150, 150, 4))
test.assert_equal(image.dtype, "uint8")

@then(u'the canvas can be rendered to a half scale png document')
def step_impl(context):
png = context.backend.render(context.canvas, scale=0.5)
image = testing.read_png(io.BytesIO(png))
nose.tools.assert_equal(image.shape, (300, 300, 4))
nose.tools.assert_equal(image.dtype, "uint8")
test.assert_equal(image.shape, (300, 300, 4))
test.assert_equal(image.dtype, "uint8")


@then(u'the canvas can be rendered to an svg file')
def step_impl(context):
target = os.path.join(testing.backend_dir, "%s.svg" % context.name)
context.backend.render(context.canvas, target)
svg = xml.parse(target)
nose.tools.assert_equal(svg.getroot().tag, "{http://www.w3.org/2000/svg}svg")
test.assert_equal(svg.getroot().tag, "{http://www.w3.org/2000/svg}svg")


@then(u'the canvas can be rendered to an svg buffer')
def step_impl(context):
buffer = io.BytesIO()
context.backend.render(context.canvas, buffer)
#svg = xml.parse(buffer.getvalue())
#nose.tools.assert_equal(svg.getroot().tag, "svg")
#test.assert_equal(svg.getroot().tag, "svg")


@then(u'the canvas can be rendered to a returned svg dom')
def step_impl(context):
svg = context.backend.render(context.canvas)
nose.tools.assert_is_instance(svg, xml.Element)
nose.tools.assert_equal(svg.tag, "svg")
test.assert_is_instance(svg, xml.Element)
test.assert_equal(svg.tag, "svg")
1 change: 0 additions & 1 deletion features/steps/bar-visualization.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

import collections

import nose.tools
import numpy.testing
import toyplot

Expand Down
10 changes: 5 additions & 5 deletions features/steps/browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from behave import *

import nose.tools
import test
import numpy
import sys
import toyplot.browser
Expand All @@ -17,10 +17,10 @@ def step_impl(context):
canvas, axes, mark = toyplot.plot(numpy.sin(numpy.linspace(0, 10)))
with unittest.mock.patch("webbrowser.open") as webbrowser_open:
toyplot.browser.show(canvas)
nose.tools.assert_equal(webbrowser_open.call_count, 1)
nose.tools.assert_true(
test.assert_equal(webbrowser_open.call_count, 1)
test.assert_true(
webbrowser_open.call_args[0][0].startswith("file://"))
nose.tools.assert_equal(webbrowser_open.call_args[1]["new"], 1)
nose.tools.assert_equal(webbrowser_open.call_args[1]["autoraise"], True)
test.assert_equal(webbrowser_open.call_args[1]["new"], 1)
test.assert_equal(webbrowser_open.call_args[1]["autoraise"], True)


8 changes: 4 additions & 4 deletions features/steps/canvas.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import io

import nose.tools
import test
import numpy.testing
import toyplot

Expand Down Expand Up @@ -65,14 +65,14 @@ def step_impl(context):
@then(u'the canvas can be rendered in Jupyter as HTML')
def step_impl(context):
html = context.canvas._repr_html_()
nose.tools.assert_is_instance(html, str)
test.assert_is_instance(html, str)

@then(u'the canvas can be rendered in Jupyter as a PNG image')
def step_impl(context):
png = context.canvas._repr_png_()
image = testing.read_png(io.BytesIO(png))
nose.tools.assert_equal(image.shape, (600, 600, 4))
nose.tools.assert_equal(image.dtype, "uint8")
test.assert_equal(image.shape, (600, 600, 4))
test.assert_equal(image.dtype, "uint8")

@then(u'numberlines can be added to the canvas using relative coordinates')
def step_impl(context):
Expand Down
Loading

0 comments on commit 58473cf

Please sign in to comment.