2 if sys
.path
[0] != "../..":
3 sys
.path
.insert(0, "../..")
8 from pyx
.graph
import data
10 class DataTestCase(unittest
.TestCase
):
13 mydata
= data
.points([[1, 2, 3], [4, 5, 6]], a
=1, b
=2)
14 self
.assertEqual(mydata
.columndata
[0], [1, 2])
15 self
.assertEqual(mydata
.columns
["a"], [1, 4])
16 self
.assertEqual(mydata
.columndata
[2], [2, 5])
17 self
.assertEqual("c" in list(mydata
.columns
.keys()), 0)
20 mydata
= data
.values(a
=[1, 4])
21 self
.assertEqual(mydata
.columns
["a"], [1, 4])
22 self
.assertEqual("c" in list(mydata
.columns
.keys()), 0)
25 mydata
= data
.points([[1], [2]], a
=1)
26 mydata2
= data
.data(mydata
, a
="2*a", b
="2*$1*a", c
="4*$(i)*a*$(-1)", context
={"i":1})
27 self
.assertEqual(mydata
.columns
["a"], [1, 2])
28 self
.assertAlmostEqual(mydata2
.columns
["a"][0], 2.0)
29 self
.assertAlmostEqual(mydata2
.columns
["a"][1], 4.0)
30 self
.assertAlmostEqual(mydata2
.columns
["b"][0], 2.0)
31 self
.assertAlmostEqual(mydata2
.columns
["b"][1], 8.0)
32 self
.assertAlmostEqual(mydata2
.columns
["c"][0], 4.0)
33 self
.assertAlmostEqual(mydata2
.columns
["c"][1], 32.0)
34 mydata3
= data
.data(mydata2
, a
="b", b
="2*c")
35 self
.assertEqual(mydata3
.columns
["a"], mydata2
.columns
["b"])
36 self
.assertAlmostEqual(mydata3
.columns
["b"][0], 2*mydata2
.columns
["c"][0])
37 self
.assertAlmostEqual(mydata3
.columns
["b"][1], 2*mydata2
.columns
["c"][1])
42 mydata
= data
.points([[1], [2]], a
=1)
43 mydata2
= data
.data(mydata
, b
="two*a", c
="two*$1*a", d
="f($1)", context
=locals())
44 self
.assertEqual(mydata
.columndata
[0], [1, 2])
45 self
.assertAlmostEqual(mydata2
.columns
["b"][0], 2.0)
46 self
.assertAlmostEqual(mydata2
.columns
["b"][1], 4.0)
47 self
.assertAlmostEqual(mydata2
.columns
["c"][0], 2.0)
48 self
.assertAlmostEqual(mydata2
.columns
["c"][1], 8.0)
49 self
.assertAlmostEqual(mydata2
.columns
["d"][0], 1.0)
50 self
.assertAlmostEqual(mydata2
.columns
["d"][1], 4.0)
53 testfile
= io
.StringIO("""#a
58 mydata
= data
.file(testfile
, row
=0, a
="a", b
=2)
59 self
.assertEqual(mydata
.columns
["row"], [1, 2, 3, 4])
60 self
.assertAlmostEqual(mydata
.columns
["a"][0], 0.0)
61 self
.assertAlmostEqual(mydata
.columns
["a"][1], 1.0)
62 self
.assertAlmostEqual(mydata
.columns
["a"][2], 2.0)
63 self
.assertAlmostEqual(mydata
.columns
["a"][3], 3.0)
64 self
.assertEqual(mydata
.columns
["b"][0], None)
65 self
.assertEqual(mydata
.columns
["b"][1], "eins")
66 self
.assertEqual(mydata
.columns
["b"][2], "2")
67 self
.assertEqual(mydata
.columns
["b"][3], "x\"x")
68 testfile
= io
.StringIO("""#a
79 mydata
= data
.file(testfile
, title
="title", skiphead
=3, skiptail
=2, every
=2, row
=0)
80 self
.assertEqual(mydata
.columns
["row"], [4, 6, 8])
81 self
.assertEqual(mydata
.title
, "title")
84 testfile
= io
.StringIO("""[sec1]
98 mydata
= data
.conffile(testfile
, sec
=0, a
="opt1", b
="opt2", c
="opt3", d
="val")
99 self
.assertEqual(mydata
.columns
["sec"], ["sec1", "sec2"])
100 self
.assertEqual(mydata
.columns
["a"], ["a1", "a4"])
101 self
.assertEqual(mydata
.columns
["b"], ["a2", "a5"])
102 self
.assertEqual(mydata
.columns
["c"], ["a3", None])
103 self
.assertAlmostEqual(mydata
.columns
["d"][0], 2.0)
104 self
.assertAlmostEqual(mydata
.columns
["d"][1], 1.0)
106 def testParamfunction(self
):
107 mydata
= data
.paramfunction("k", 0, 9, "x, y = k, -k", points
=10)
109 self
.assertEqual(mydata
.columns
["x"][i
], i
)
110 self
.assertEqual(mydata
.columns
["y"][i
], -i
)
113 if __name__
== "__main__":