def eval_code(sceneobj, verbose=True): assert sceneobj.isValid() hasname = sceneobj.isNamed() if not hasname: sceneobj.name = 'testedobject' fname = 'geomprinteroutput.geom' printer = pgl.PglFilePrinter(fname) sceneobj.apply(printer) txt = open(fname, 'r').read() printer = pgl.PglStrPrinter() sceneobj.apply(printer) txt2 = printer.str() print(repr(txt)) print(repr(txt2)) assert txt == txt2 if verbose: print(txt) if 'PGL_ASCII_PARSER' in pgl.get_pgl_supported_extensions(): b = pgl.isPglParserVerbose() pgl.pglParserVerbose(False) print('read') sc, dic = pgl.pgl_read(txt) pgl.pglParserVerbose(b) if sceneobj.name not in dic: print(txt) assert "evaluated object not found" eval_object = dic[sceneobj.name] assert type(eval_object) == type( sceneobj) and eval_object.name == sceneobj.name if not hasname: sceneobj.name = '' return eval_object else: return sceneobj
def test_parser_already_declared_error(): txt = """Group test { GeometryList [ Sphere test { } ] }""" b = pgl.isPglParserVerbose() pgl.pglParserVerbose(False) if 'PGL_ASCII_PARSER' in pgl.get_pgl_supported_extensions(): sc, dic = pgl.pgl_read(txt) pgl.pglParserVerbose(b)
def eval_code(sceneobj, verbose=True): assert sceneobj.isValid() hasname = sceneobj.isNamed() if not hasname: sceneobj.name = 'testedobject' printer = pgl.PglStrPrinter() sceneobj.apply(printer) txt = printer.str() if verbose: print txt if 'PGL_ASCII_PARSER' in pgl.get_pgl_supported_extensions(): b = pgl.isPglParserVerbose() pgl.pglParserVerbose(False) sc, dic = pgl.pgl_read(txt) pgl.pglParserVerbose(b) if not dic.has_key(sceneobj.name): print txt assert "evaluated object not found" eval_object = dic[sceneobj.name] assert type(eval_object) == type( sceneobj) and eval_object.name == sceneobj.name if not hasname: sceneobj.name = '' return eval_object else: return sceneobj
def test_longid(): txt = ''' Shape s0 { Id 2599904224 Geometry Sphere{} Appearance Material {} } ''' b = pgl.isPglParserVerbose() pgl.pglParserVerbose(False) if 'PGL_ASCII_PARSER' in pgl.get_pgl_supported_extensions(): sc, dic = pgl.pgl_read(txt) pgl.pglParserVerbose(b)