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)
Exemple #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)
Exemple #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')
Exemple #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)
Exemple #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)
Exemple #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)
    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)
Exemple #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)
Exemple #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.)
Exemple #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)
Exemple #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)
Exemple #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)
Exemple #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)
Exemple #14
0
 def test_stl_instantiation(self):
     stl_handler = sh.StlHandler()
Exemple #15
0
 def test_stl_default_extension_member(self):
     stl_handler = sh.StlHandler()
     self.assertListEqual(stl_handler.extensions, ['.stl'])
Exemple #16
0
 def test_stl_plot_failing_outfile_type(self):
     stl_handler = sh.StlHandler()
     with self.assertRaises(TypeError):
         stl_handler.plot(plot_file=3)
Exemple #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)
Exemple #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')
Exemple #19
0
 def test_stl_show_fail(self):
     stl_handler = sh.StlHandler()
     with self.assertRaises(TypeError):
         stl_handler.show(show_file=3)
Exemple #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)
Exemple #21
0
 def test_stl_default_outfile_member(self):
     stl_handler = sh.StlHandler()
     assert stl_handler.outfile == None
Exemple #22
0
 def test_stl_default_outfile_member(self):
     stl_handler = sh.StlHandler()
     self.assertIsNone(stl_handler.outfile)
Exemple #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')
Exemple #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'
Exemple #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')
Exemple #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)
Exemple #27
0
 def test_stl_default_extension_member(self):
     stl_handler = sh.StlHandler()
     assert stl_handler.extension == '.stl'
Exemple #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))