/usr/lib/python2.7/dist-packages/chaco/tests/arraydatasource_test_case.py is in python-chaco 4.5.0-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 | """
Test of basic dataseries behavior.
"""
import unittest
from numpy import arange, array, allclose, empty, isnan, nan
import numpy as np
from chaco.api import ArrayDataSource, PointDataSource
class ArrayDataTestCase(unittest.TestCase):
def test_basic_set_get(self):
myarray = arange(10)
sd = ArrayDataSource(myarray)
self.assertTrue(allclose(myarray, sd._data))
self.assert_(sd.value_dimension == "scalar")
return
def test_bounds(self):
# ascending
myarray = arange(10)
sd = ArrayDataSource(myarray, sort_order="ascending")
bounds = sd.get_bounds()
self.assert_(bounds == (0,9))
# descending
myarray = arange(10)[::-1]
sd = ArrayDataSource(myarray, sort_order="descending")
bounds = sd.get_bounds()
self.assert_(bounds == (0,9))
# no order
myarray = array([12,3,0,9,2,18,3])
sd = ArrayDataSource(myarray, sort_order="none")
bounds = sd.get_bounds()
self.assert_(bounds == (0,18))
return
def test_data_size(self):
# We know that ScalarData always returns the exact length of its data
myarray = arange(913)
sd = ArrayDataSource(myarray)
self.assert_(len(myarray) == sd.get_size())
return
def test_bounds_all_nans(self):
myarray = empty(10)
myarray[:] = nan
sd = ArrayDataSource(myarray)
bounds = sd.get_bounds()
self.assertTrue(isnan(bounds[0]))
self.assertTrue(isnan(bounds[1]))
def test_bounds_non_numeric(self):
myarray = np.array([u'abc', u'foo', u'bar', u'def'], dtype=unicode)
sd = ArrayDataSource(myarray)
bounds = sd.get_bounds()
self.assertEqual(bounds, (u'abc', u'def'))
class PointDataTestCase(unittest.TestCase):
# Since PointData is mostly the same as ScalarData, the key things to
# test are functionality that use _compute_bounds() and reverse_map().
def create_array(self):
return array(zip(range(10), range(0, 100, 10)))
def test_basic_set_get(self):
myarray = self.create_array()
pd = PointDataSource(myarray)
self.assertTrue(allclose(myarray,pd._data))
self.assert_(pd.value_dimension == "point")
return
def test_bounds(self):
myarray = self.create_array()
pd = PointDataSource(myarray)
self.assertEqual(pd.get_bounds(),((0,0), (9,90)))
return
if __name__ == '__main__':
import nose
nose.run()
|