散景图的单元测试
Unit test of Bokeh plot
我是单元测试和 Bokeh 的初学者。我如何测试散景图是否确实存在并且属于正确的 class?
from bokeh.plotting import figure
p = figure(...)
..
assert isinstance(p, type(figure)), 'it is not a bokeh plot'
returns 'it is not a bokeh plot'...
查看 class 的字符串会比创建对象和比较实例更容易吗?
import unittest
from bokeh.plotting import figure
class BokehScriptTest(unittest.TestCase):
def test_plot(self):
p = figure()
self.assertEqual(str(type(p)),"<class 'bokeh.plotting.figure.Figure'>")
所以我们有了对象 p,访问它的类型,并获取字符串。它还可以更轻松地查看您期望得到的结果。
我是单元测试和 Bokeh 的初学者。我如何测试散景图是否确实存在并且属于正确的 class?
from bokeh.plotting import figure
p = figure(...)
..
assert isinstance(p, type(figure)), 'it is not a bokeh plot'
returns 'it is not a bokeh plot'...
查看 class 的字符串会比创建对象和比较实例更容易吗?
import unittest
from bokeh.plotting import figure
class BokehScriptTest(unittest.TestCase):
def test_plot(self):
p = figure()
self.assertEqual(str(type(p)),"<class 'bokeh.plotting.figure.Figure'>")
所以我们有了对象 p,访问它的类型,并获取字符串。它还可以更轻松地查看您期望得到的结果。