1- import filecmp
2- import os
31from unittest import TestCase
4-
5- import numpy as np
6-
2+ import unittest
73import pygem .elmerhandler as elh
4+ import numpy as np
5+ import filecmp
6+ import os
87
98
109class TestElmerHandler (TestCase ):
1110 def test_elmer_instantiation (self ):
12- elh .ElmerHandler ()
13-
11+ elmer_handler = elh .ElmerHandler ()
12+
1413 def test_elmer_default_infile_member (self ):
1514 elmer_handler = elh .ElmerHandler ()
1615 self .assertIsNone (elmer_handler .infile )
@@ -21,112 +20,97 @@ def test_elmer_default_outfile_member(self):
2120
2221 def test_elmer_default_extension_member (self ):
2322 elmer_handler = elh .ElmerHandler ()
24- self .assertListEqual (elmer_handler .extensions , [" .nodes" ])
23+ self .assertListEqual (elmer_handler .extensions , [' .nodes' ])
2524
2625 def test_elmer_parse_failing_filename_type (self ):
2726 elmer_handler = elh .ElmerHandler ()
2827 with self .assertRaises (TypeError ):
29- elmer_handler .parse (0 .2 )
28+ mesh_points = elmer_handler .parse (.2 )
3029
3130 def test_elmer_parse_failing_check_extension (self ):
3231 elmer_handler = elh .ElmerHandler ()
3332 with self .assertRaises (ValueError ):
3433 mesh_points = elmer_handler .parse (
35- "tests/test_datasets/test_square.iges"
36- )
34+ 'tests/test_datasets/test_square.iges' )
3735
3836 def test_elmer_parse_infile (self ):
3937 elmer_handler = elh .ElmerHandler ()
4038 mesh_points = elmer_handler .parse (
41- "tests/test_datasets/test_elmer.nodes"
42- )
43- self .assertEqual (
44- elmer_handler .infile , "tests/test_datasets/test_elmer.nodes"
45- )
39+ 'tests/test_datasets/test_elmer.nodes' )
40+ self .assertEqual (elmer_handler .infile ,
41+ 'tests/test_datasets/test_elmer.nodes' )
4642
4743 def test_elmer_parse_shape (self ):
4844 elmer_handler = elh .ElmerHandler ()
4945 mesh_points = elmer_handler .parse (
50- "tests/test_datasets/test_elmer.nodes"
51- )
46+ 'tests/test_datasets/test_elmer.nodes' )
5247 self .assertTupleEqual (mesh_points .shape , (240 , 3 ))
5348
5449 def test_elmer_parse_coords_1 (self ):
5550 elmer_handler = elh .ElmerHandler ()
5651 mesh_points = elmer_handler .parse (
57- "tests/test_datasets/test_elmer.nodes"
58- )
52+ 'tests/test_datasets/test_elmer.nodes' )
5953 np .testing .assert_almost_equal (mesh_points [33 ][0 ], 2.94650796191 )
6054
6155 def test_open_foam_parse_coords_2 (self ):
6256 elmer_handler = elh .ElmerHandler ()
6357 mesh_points = elmer_handler .parse (
64- "tests/test_datasets/test_elmer.nodes"
65- )
58+ 'tests/test_datasets/test_elmer.nodes' )
6659 np .testing .assert_almost_equal (mesh_points [149 ][1 ], 2 )
6760
6861 def test_elmer_parse_coords_3 (self ):
6962 elmer_handler = elh .ElmerHandler ()
7063 mesh_points = elmer_handler .parse (
71- "tests/test_datasets/test_elmer.nodes"
72- )
73- np .testing .assert_almost_equal (mesh_points [239 ][2 ], 0.0 )
64+ 'tests/test_datasets/test_elmer.nodes' )
65+ np .testing .assert_almost_equal (mesh_points [239 ][2 ], .0 )
7466
7567 def test_elmer_parse_coords_4 (self ):
7668 elmer_handler = elh .ElmerHandler ()
7769 mesh_points = elmer_handler .parse (
78- "tests/test_datasets/test_elmer.nodes"
79- )
70+ 'tests/test_datasets/test_elmer.nodes' )
8071 np .testing .assert_almost_equal (mesh_points [0 ][0 ], 0.0 )
8172
8273 def test_elmer_parse_coords_5 (self ):
8374 elmer_handler = elh .ElmerHandler ()
8475 mesh_points = elmer_handler .parse (
85- "tests/test_datasets/test_elmer.nodes"
86- )
76+ 'tests/test_datasets/test_elmer.nodes' )
8777 np .testing .assert_almost_equal (mesh_points [- 1 ][1 ], 2 )
8878
8979 def test_elmer_write_failing_filename_type (self ):
9080 elmer_handler = elh .ElmerHandler ()
9181 mesh_points = elmer_handler .parse (
92- "tests/test_datasets/test_elmer.nodes"
93- )
82+ 'tests/test_datasets/test_elmer.nodes' )
9483 with self .assertRaises (TypeError ):
95- elmer_handler .write (mesh_points , - 1.0 )
84+ elmer_handler .write (mesh_points , - 1. )
9685
9786 def test_elmer_write_failing_check_extension (self ):
9887 elmer_handler = elh .ElmerHandler ()
9988 mesh_points = elmer_handler .parse (
100- "tests/test_datasets/test_elmer.nodes"
101- )
89+ 'tests/test_datasets/test_elmer.nodes' )
10290 with self .assertRaises (ValueError ):
103- elmer_handler .write (
104- mesh_points , "tests/test_datasets/test_square.iges"
105- )
91+ elmer_handler .write (mesh_points ,
92+ 'tests/test_datasets/test_square.iges' )
10693
10794 def test_elmer_write_failing_infile_instantiation (self ):
10895 elmer_handler = elh .ElmerHandler ()
10996 mesh_points = np .zeros ((40 , 3 ))
11097 with self .assertRaises (RuntimeError ):
111- elmer_handler .write (
112- mesh_points , "tests/test_datasets/test_elmer_out.nodes"
113- )
98+ elmer_handler .write (mesh_points ,
99+ 'tests/test_datasets/test_elmer_out.nodes' )
114100
115101 def test_elmer_write_outfile (self ):
116102 elmer_handler = elh .ElmerHandler ()
117103 mesh_points = elmer_handler .parse (
118- "tests/test_datasets/test_elmer.nodes"
119- )
120- outfilename = "tests/test_datasets/test_elmer_out.nodes"
104+ 'tests/test_datasets/test_elmer.nodes' )
105+ outfilename = 'tests/test_datasets/test_elmer_out.nodes'
121106 elmer_handler .write (mesh_points , outfilename )
122107 self .assertEqual (elmer_handler .outfile , outfilename )
123108 self .addCleanup (os .remove , outfilename )
124109
125110 def test_elmer_write_comparison (self ):
126111 elmer_handler = elh .ElmerHandler ()
127112 mesh_points = elmer_handler .parse (
128- "tests/test_datasets/test_elmer.nodes"
129- )
113+ 'tests/test_datasets/test_elmer.nodes' )
130114 mesh_points [0 ] = [0.1 , 1.1 , 0.1 ]
131115 mesh_points [1 ] = [0.1 , 1.2 , 0.1 ]
132116 mesh_points [2 ] = [0.1 , 1.6 , 0.1 ]
@@ -136,9 +120,9 @@ def test_elmer_write_comparison(self):
136120 mesh_points [- 3 ] = [26.2 , 1.6 , 0.1 ]
137121 mesh_points [- 2 ] = [26.2 , 2.01666666667 , 0.1 ]
138122 mesh_points [- 1 ] = [26.2 , 2.1 , 0.1 ]
139-
140- outfilename = " tests/test_datasets/test_elmer_out.nodes"
141- outfilename_expected = " tests/test_datasets/test_elmer_out_true.nodes"
123+
124+ outfilename = ' tests/test_datasets/test_elmer_out.nodes'
125+ outfilename_expected = ' tests/test_datasets/test_elmer_out_true.nodes'
142126
143127 elmer_handler .write (mesh_points , outfilename )
144128 self .assertTrue (filecmp .cmp (outfilename , outfilename_expected ))
0 commit comments