def test_visitor(self): path = os.path.join(os.path.dirname(__file__), 'data') for item in os.listdir(path): fn, ext = os.path.splitext(item) if ext != '.xml': continue name, expect = os.path.splitext(fn) item_path = os.path.join(path, item) try: cfg = ConfigSource().load(item_path) except Exception, e: if expect != '.fail': raise if not isinstance(e, ParseError): raise else: self.assertEqual(expect, '.succ') if hasattr(self, 'check_%s' % name): getattr(self, 'check_%s' % name)(cfg) with make_tempfile(suffix='.xml') as (fd, fn): os.write(fd, save_config(cfg)) ConfigSource().load(fn) if ext == '.xml': self.assertEqual(clean(save_config(cfg)), clean(open(item_path).read()))#, 'The newly saved config does not equal %s' % (item_path,))
def __run(self): with make_tempfile() as (fd, fn): cur = os.getcwd() try: os.chdir(os.path.join(exampledir, name)) rc = os.system('../../cgx make -f -v debug 2>%s' % fn) if rc == 0: rc = os.system('../../cgx clean -v debug 2>>%s' % fn) finally: os.chdir(cur) if rc != 0: print >> sys.stderr, "stderr output from 'cgx build -f'" sys.stderr.write(open(fn, 'r').read()) self.assertEqual(rc, 0)
def test_load_file_with_locator(self): loc = FileResourceLocator("/tmp") with make_tempfile() as (fd, name): os.write(fd, xml_content) self.check(self.source.load(resource=os.path.basename(name), resource_locator=loc))
def test_load_file_without_locator(self): with make_tempfile() as (fd, name): os.write(fd, xml_content) self.check(self.source.load(resource=name))