d9d59d70d6c96300d23235c4de6aef9ba7b4b9f8
[python-bulletml.git] / test_examples.py
1 import os
2 import glob
3
4 from bulletml import BulletML, Bullet, bulletyaml
5 from tests import TestCase, add
6
7 class Texamples_xml(TestCase):
8 pass
9
10 class Texamples_yaml(TestCase):
11 pass
12
13 class Texamples_repr(TestCase):
14 pass
15
16 class Texamples_run(TestCase):
17 pass
18
19 for filename in glob.glob("examples/*/*.xml"):
20 basename = os.path.basename(filename)[:-4].replace("-", "_")
21
22 def test_xml(self, filename=filename):
23 BulletML.FromDocument(open(filename, "rU"))
24 setattr(Texamples_xml, "test_" + basename, test_xml)
25
26 try:
27 import yaml
28 except ImportError:
29 pass
30 else:
31 def test_yaml(self, filename=filename):
32 doc = BulletML.FromDocument(open(filename, "rU"))
33 doc = yaml.load(yaml.dump(doc))
34 doc = yaml.load(yaml.dump(doc))
35 setattr(Texamples_yaml, "test_" + basename, test_yaml)
36
37 def test_repr(self, filename=filename):
38 doc = BulletML.FromDocument(open(filename, "rU"))
39 repr(doc)
40 setattr(Texamples_repr, "test_" + basename, test_repr)
41
42 def test_run(self, filename=filename):
43 doc = BulletML.FromDocument(open(filename, "rU"))
44 bullets = [Bullet.FromDocument(doc)]
45 for i in range(100):
46 for bullet in bullets:
47 bullets.extend(bullet.step())
48 setattr(Texamples_run, "test_" + basename, test_run)
49
50
51 add(Texamples_xml)
52 add(Texamples_yaml)
53 add(Texamples_repr)
54 add(Texamples_run)