1 # -*- coding: iso-8859-1 -*-
4 from hoomd_script
import *
8 # unit tests for init.read_xml
9 class init_read_xml_tests (unittest
.TestCase
):
12 if (comm
.get_rank()==0):
13 f
= open("test.xml", "w");
14 f
.write('''<?xml version="1.0" encoding="UTF-8"?>
15 <hoomd_xml version="1.0">
16 <configuration time_step="0">
17 <box lx="8" ly="8" lz="8"/>
29 f
= open("test_out_of_box.xml", "w");
30 f
.write('''<?xml version="1.0" encoding="UTF-8"?>
31 <hoomd_xml version="1.0">
32 <configuration time_step="0">
33 <box lx="4" ly="4" lz="4"/>
46 # tests basic creation of the random initializer
48 init
.read_xml('test.xml');
49 self
.assert_(globals.system_definition
);
50 self
.assert_(globals.system
);
51 self
.assertEqual(globals.system_definition
.getParticleData().getNGlobal(), 3);
53 # tests creation with a few more arugments specified
54 def test_moreargs(self
):
55 init
.read_xml('test.xml', time_step
=100);
56 self
.assert_(globals.system_definition
);
57 self
.assert_(globals.system
);
58 self
.assertEqual(globals.system_definition
.getParticleData().getNGlobal(), 3);
60 # tests creation with out of box particles
61 def test_out_of_box_1(self
):
62 self
.assertRaises(RuntimeError, init
.read_xml
, 'test_out_of_box.xml')
64 # tests creation with out of box particles
65 def test_out_of_box_2(self
):
66 sys
=init
.read_xml('test_out_of_box.xml',wrap_coordinates
=True)
67 self
.assert_(globals.system_definition
);
68 self
.assert_(globals.system
);
69 self
.assertEqual(globals.system_definition
.getParticleData().getNGlobal(), 3);
70 self
.assertAlmostEqual(sys
.particles
[0].position
[2],-1,5)
72 # checks for an error if initialized twice
73 def test_inittwice(self
):
74 init
.read_xml('test.xml');
75 self
.assertRaises(RuntimeError, init
.read_xml
, 'test.xml');
78 if (comm
.get_rank()==0):
79 os
.remove("test.xml");
80 os
.remove("test_out_of_box.xml");
83 if __name__
== '__main__':
84 unittest
.main(argv
= ['test.py', '-v'])