Ejemplo n.º 1
0
 def test_stl_write_outfile(self):
     stl_handler = sh.StlHandler()
     mesh_points = stl_handler.parse('tests/test_datasets/test_sphere.stl')
     outfilename = 'tests/test_datasets/test_sphere_out.stl'
     stl_handler.write(mesh_points, outfilename)
     self.assertEqual(stl_handler.outfile, outfilename)
     self.addCleanup(os.remove, outfilename)
Ejemplo n.º 2
0
 def test_stl_write_outfile(self):
     stl_handler = sh.StlHandler()
     mesh_points = stl_handler.parse('tests/test_datasets/test_sphere.stl')
     outfilename = 'tests/test_datasets/test_sphere_out.stl'
     stl_handler.write(mesh_points, outfilename)
     assert stl_handler.outfile == outfilename
     os.remove(outfilename)
Ejemplo n.º 3
0
 def test_stl_plot_save_fig_bin(self):
     stl_handler = sh.StlHandler()
     mesh_points = stl_handler.parse(
         'tests/test_datasets/test_sphere_bin.stl')
     stl_handler.plot(save_fig=True)
     self.assertTrue(
         os.path.isfile('tests/test_datasets/test_sphere_bin.png'))
     os.remove('tests/test_datasets/test_sphere_bin.png')
Ejemplo n.º 4
0
    def test_stl_write_binary_from_ascii(self):
        stl_handler = sh.StlHandler()
        mesh_points = stl_handler.parse('tests/test_datasets/test_sphere.stl')
        mesh_points[0] = [-40.2, -20.5, 60.9]
        mesh_points[1] = [-40.2, -10.5, 60.9]
        mesh_points[2] = [-40.2, -10.5, 60.9]
        mesh_points[2000] = [-40.2, -20.5, 60.9]
        mesh_points[2001] = [-40.2, -10.5, 60.9]
        mesh_points[2002] = [-40.2, -10.5, 60.9]
        mesh_points[6100] = [-40.2, -20.5, 60.9]
        mesh_points[6101] = [-40.2, -10.5, 60.9]
        mesh_points[6102] = [-40.2, -10.5, 60.9]

        outfilename = 'tests/test_datasets/test_sphere_out.stl'

        stl_handler.write(mesh_points, outfilename, write_bin=True)
        os.remove(outfilename)
Ejemplo n.º 5
0
    def test_stl_write_binary_from_binary(self):
        stl_handler = sh.StlHandler()
        mesh_points = stl_handler.parse(
            'tests/test_datasets/test_sphere_bin.stl')
        mesh_points[0] = [-40.2, -20.5, 60.9]
        mesh_points[1] = [-40.2, -10.5, 60.9]
        mesh_points[2] = [-40.2, -10.5, 60.9]
        mesh_points[500] = [-40.2, -20.5, 60.9]
        mesh_points[501] = [-40.2, -10.5, 60.9]
        mesh_points[502] = [-40.2, -10.5, 60.9]
        mesh_points[1000] = [-40.2, -20.5, 60.9]
        mesh_points[1001] = [-40.2, -10.5, 60.9]
        mesh_points[1002] = [-40.2, -10.5, 60.9]

        outfilename = 'tests/test_datasets/test_sphere_out.stl'

        stl_handler.write(mesh_points, outfilename, write_bin=True)
        self.addCleanup(os.remove, outfilename)
Ejemplo n.º 6
0
    def test_stl_write_comparison(self):
        stl_handler = sh.StlHandler()
        mesh_points = stl_handler.parse('tests/test_datasets/test_sphere.stl')
        mesh_points[0] = [-40.2, -20.5, 60.9]
        mesh_points[1] = [-40.2, -10.5, 60.9]
        mesh_points[2] = [-40.2, -10.5, 60.9]
        mesh_points[2000] = [-40.2, -20.5, 60.9]
        mesh_points[2001] = [-40.2, -10.5, 60.9]
        mesh_points[2002] = [-40.2, -10.5, 60.9]
        mesh_points[6100] = [-40.2, -20.5, 60.9]
        mesh_points[6101] = [-40.2, -10.5, 60.9]
        mesh_points[6102] = [-40.2, -10.5, 60.9]

        outfilename = 'tests/test_datasets/test_sphere_out.stl'
        outfilename_expected = 'tests/test_datasets/test_sphere_out_true.stl'

        stl_handler.write(mesh_points, outfilename)
        self.assertTrue(filecmp.cmp(outfilename, outfilename_expected))
        os.remove(outfilename)
Ejemplo n.º 7
0
    def test_stl_write_ascii_from_binary(self):
        stl_handler = sh.StlHandler()
        mesh_points = stl_handler.parse(
            'tests/test_datasets/test_sphere_bin.stl')
        mesh_points[0] = [-40.2, -20.5, 60.9]
        mesh_points[1] = [-40.2, -10.5, 60.9]
        mesh_points[2] = [-40.2, -10.5, 60.9]
        mesh_points[2000] = [-40.2, -20.5, 60.9]
        mesh_points[2001] = [-40.2, -10.5, 60.9]
        mesh_points[2002] = [-40.2, -10.5, 60.9]
        mesh_points[6100] = [-40.2, -20.5, 60.9]
        mesh_points[6101] = [-40.2, -10.5, 60.9]
        mesh_points[6102] = [-40.2, -10.5, 60.9]

        outfilename = 'tests/test_datasets/test_sphere_out.stl'
        outfilename_expected = 'tests/test_datasets/test_sphere_out_true.stl'

        stl_handler.write(mesh_points, outfilename, write_bin=False)
        self.assertTrue(filecmp.cmp(outfilename, outfilename_expected))
        self.addCleanup(os.remove, outfilename)
Ejemplo n.º 8
0
    def test_stl_write_comparison(self):
        stl_handler = sh.StlHandler()
        mesh_points = stl_handler.parse('tests/test_datasets/test_sphere.stl')
        mesh_points[0] = [-40.2, -20.5, 60.9]
        mesh_points[1] = [-40.2, -10.5, 60.9]
        mesh_points[2] = [-40.2, -10.5, 60.9]
        mesh_points[500] = [-40.2, -20.5, 60.9]
        mesh_points[501] = [-40.2, -10.5, 60.9]
        mesh_points[502] = [-40.2, -10.5, 60.9]
        mesh_points[1000] = [-40.2, -20.5, 60.9]
        mesh_points[1001] = [-40.2, -10.5, 60.9]
        mesh_points[1002] = [-40.2, -10.5, 60.9]

        outfilename = 'tests/test_datasets/test_sphere_out.stl'
        outfilename_expected = 'tests/test_datasets/test_sphere_out_true.stl'

        stl_handler.write(mesh_points, outfilename)
        with open(outfilename, 'r') as out, open(outfilename_expected, 'r') as exp:
            self.assertTrue(out.readlines()[1:] == exp.readlines()[1:])
        self.addCleanup(os.remove, outfilename)
Ejemplo n.º 9
0
 def test_stl_write_failing_filename_type(self):
     stl_handler = sh.StlHandler()
     mesh_points = stl_handler.parse('tests/test_datasets/test_sphere.stl')
     with self.assertRaises(TypeError):
         stl_handler.write(mesh_points, 4.)
Ejemplo n.º 10
0
 def test_stl_parse_coords_4(self):
     stl_handler = sh.StlHandler()
     mesh_points = stl_handler.parse('tests/test_datasets/test_sphere.stl')
     np.testing.assert_almost_equal(mesh_points[0][0], -21.31975937)
Ejemplo n.º 11
0
 def test_stl_parse_coords_5_bin(self):
     stl_handler = sh.StlHandler()
     mesh_points = stl_handler.parse(
         'tests/test_datasets/test_sphere_bin.stl')
     np.testing.assert_almost_equal(mesh_points[-1][2], -39.05963898)
Ejemplo n.º 12
0
 def test_stl_parse_coords_2(self):
     stl_handler = sh.StlHandler()
     mesh_points = stl_handler.parse('tests/test_datasets/test_sphere.stl')
     np.testing.assert_almost_equal(mesh_points[1708][1], 2.58431911)
Ejemplo n.º 13
0
 def test_stl_parse_coords_3(self):
     stl_handler = sh.StlHandler()
     mesh_points = stl_handler.parse('tests/test_datasets/test_sphere.stl')
     np.testing.assert_almost_equal(mesh_points[3527][2], -2.47207999)
Ejemplo n.º 14
0
 def test_stl_instantiation(self):
     stl_handler = sh.StlHandler()
Ejemplo n.º 15
0
 def test_stl_default_extension_member(self):
     stl_handler = sh.StlHandler()
     self.assertListEqual(stl_handler.extensions, ['.stl'])
Ejemplo n.º 16
0
 def test_stl_plot_failing_outfile_type(self):
     stl_handler = sh.StlHandler()
     with self.assertRaises(TypeError):
         stl_handler.plot(plot_file=3)
Ejemplo n.º 17
0
 def test_stl_parse_failing_filename_type(self):
     stl_handler = sh.StlHandler()
     with self.assertRaises(TypeError):
         mesh_points = stl_handler.parse(5.2)
Ejemplo n.º 18
0
 def test_stl_plot_save_fig_plot_file(self):
     stl_handler = sh.StlHandler()
     stl_handler.plot(plot_file='tests/test_datasets/test_sphere.stl',
                      save_fig=True)
     self.assertTrue(os.path.isfile('tests/test_datasets/test_sphere.png'))
     os.remove('tests/test_datasets/test_sphere.png')
Ejemplo n.º 19
0
 def test_stl_show_fail(self):
     stl_handler = sh.StlHandler()
     with self.assertRaises(TypeError):
         stl_handler.show(show_file=3)
Ejemplo n.º 20
0
 def test_stl_parse_coords_1(self):
     stl_handler = sh.StlHandler()
     mesh_points = stl_handler.parse('tests/test_datasets/test_sphere.stl')
     np.testing.assert_almost_equal(mesh_points[33][0], -17.51774978)
Ejemplo n.º 21
0
 def test_stl_default_outfile_member(self):
     stl_handler = sh.StlHandler()
     assert stl_handler.outfile == None
Ejemplo n.º 22
0
 def test_stl_default_outfile_member(self):
     stl_handler = sh.StlHandler()
     self.assertIsNone(stl_handler.outfile)
Ejemplo n.º 23
0
 def test_stl_write_failing_check_extension(self):
     stl_handler = sh.StlHandler()
     mesh_points = stl_handler.parse('tests/test_datasets/test_sphere.stl')
     with self.assertRaises(ValueError):
         stl_handler.write(mesh_points,
                           'tests/test_datasets/test_square.iges')
Ejemplo n.º 24
0
 def test_stl_parse_infile(self):
     stl_handler = sh.StlHandler()
     mesh_points = stl_handler.parse('tests/test_datasets/test_sphere.stl')
     assert stl_handler.infile == 'tests/test_datasets/test_sphere.stl'
Ejemplo n.º 25
0
 def test_stl_write_failing_infile_instantiation(self):
     stl_handler = sh.StlHandler()
     mesh_points = np.zeros((40, 3))
     with self.assertRaises(RuntimeError):
         stl_handler.write(mesh_points,
                           'tests/test_datasets/test_sphere_out.stl')
Ejemplo n.º 26
0
 def test_stl_parse_shape(self):
     stl_handler = sh.StlHandler()
     mesh_points = stl_handler.parse('tests/test_datasets/test_sphere.stl')
     assert mesh_points.shape == (7200, 3)
Ejemplo n.º 27
0
 def test_stl_default_extension_member(self):
     stl_handler = sh.StlHandler()
     assert stl_handler.extension == '.stl'
Ejemplo n.º 28
0
 def test_stl_parse_shape(self):
     stl_handler = sh.StlHandler()
     mesh_points = stl_handler.parse('tests/test_datasets/test_sphere.stl')
     self.assertTupleEqual(mesh_points.shape, (7200, 3))