def test_export(self): obj = CubeStack() f = lambda n: os.path.join(self.foldername, n) obj.exporter('json')(f('out.json')) self.assertFalse(os.path.exists(f('out.json'))) self.assertFilesizeNonZero(f('out.cube_a.json')) self.assertFilesizeNonZero(f('out.cube_b.json'))
def test_assembly(self): asm = CubeStack() asm.exporter('gltf')(os.path.join(self.foldername, 'asm.gltf')) self.assertFilesizeNonZero(os.path.join(self.foldername, 'asm.gltf')) for name in asm.components.keys( ): # only works because it's a single layer assembly self.assertFilesizeNonZero( os.path.join(self.foldername, 'asm.%s.bin' % name))
def test_prefix(self): obj = CubeStack() tree_str = obj.tree_str(name='cubestack', prefix="--") self.assertEqual( tree_str, '\n'.join([ u"--cubestack", u"-- \u251c\u25cb cube_a", u"-- \u2514\u25cb cube_b\n", ]))
def test_one_layer(self): obj = CubeStack() tree_str = obj.tree_str(name='cubestack') self.assertEqual( tree_str, '\n'.join([ u"cubestack", u" \u251c\u25cb cube_a", u" \u2514\u25cb cube_b\n", ]))
def test_no_exporter_for_type(self): @codec.register_exporter('abc', Part) class Abc(codec.Exporter): pass with self.assertRaises(TypeError): codec.get_exporter(CubeStack(), 'abc') # assembly
def test_assembly(self, mock_show): assembly = CubeStack() disp_env = display.freecad.FreeCADDisplayEnv() disp_env.display(assembly) self.assertEqual(len(mock_show.call_args_list), 2) # 2 objects for (args, kwargs) in mock_show.call_args_list: self.assertIn(args[0], map(lambda x: x.world_obj, assembly.components.values()))
def test_repr(self): obj = CubeStack() # no repr tree_str = obj.tree_str(name='cubestack', add_repr=False) for line in tree_str.rstrip('\n').split('\n'): self.assertIsNone(re.search(r'<[^>]+>', line)) # repr on each line tree_str = obj.tree_str(name='cubestack', add_repr=True) for line in tree_str.rstrip('\n').split('\n'): self.assertIsNotNone(re.search(r'<[^>]+>', line)) # repeat: nested obj obj = SimpleCar() tree_str = obj.tree_str(name='car', add_repr=True) for line in tree_str.rstrip('\n').split('\n'): self.assertIsNotNone(re.search(r'<[^>]+>', line))