コード例 #1
0
ファイル: _testbed.py プロジェクト: ateska/pyless
	def _do_file_test(self, fname):
		# Parse input file
		lexer, parser, tokens, presult = pyless.parse(fname)
		if lexer.getNumberOfSyntaxErrors() > 0:
			self.fail("Lexer errors:\n" + '\n'.join(lexer.errormsgcache))
		if parser.getNumberOfSyntaxErrors() > 0:
			self.fail("Parser errors:\n" + '\n'.join(parser.errormsgcache))

		r = presult.tree.toStringTree()
		self.assertIsNotNone(r, "Parsing silently failed!")

		# Save graph to dot
		dotout.save_result(presult, fname+".dot")

		# Tree walk
		output = StringIO.StringIO()
		twalker, tresult = pyless.twalk(presult, tokens, output=output)
		if twalker.getNumberOfSyntaxErrors() > 0:
			self.fail("Tree walker errors:\n" + '\n'.join(twalker.errormsgcache))

		output.seek(0)
		output2nd = self._reparse(output)

		# Compare outputs - must be the same
		output.seek(0)
		self.assertEqual(output.getvalue(), output2nd.getvalue())
コード例 #2
0
ファイル: _testbed.py プロジェクト: ateska/pyless
	def _reparse(self, output):
		# Reparse output CSS again
		lexer, parser, tokens, presult = pyless.parse(output)
		if lexer.getNumberOfSyntaxErrors() > 0:
			self.fail("Lexer (reparse) errors:\n" + '\n'.join(lexer.errormsgcache))
		if parser.getNumberOfSyntaxErrors() > 0:
			self.fail("Parser (reparse) errors:\n" + '\n'.join(parser.errormsgcache))

		r = presult.tree.toStringTree()
		self.assertIsNotNone(r, "Parsing (reparse) silently failed!")

		# Tree walk
		output = StringIO.StringIO()
		twalker, tresult = pyless.twalk(presult, tokens, output=output)
		if twalker.getNumberOfSyntaxErrors() > 0:
			self.fail("Tree walker errors:\n" + '\n'.join(twalker.errormsgcache))

		output.seek(0)
		return output
コード例 #3
0
	def _do_file_test(self, fname):
		lexer, parser, result = pyless.parse(fname)
		if lexer.getNumberOfSyntaxErrors() > 0:
			self.fail("Lexer errors:\n" + '\n'.join(lexer.errormsgcache))
		if parser.getNumberOfSyntaxErrors() > 0:
			self.fail("Parser errors:\n" + '\n'.join(parser.errormsgcache))

		r = result.tree.toStringTree()
		self.assertIsNotNone(r, "Parsing silently failed!")

		###

		fout = open(fname+'.dot', "w")
		fout.write('digraph {0} {{\nratio="fill";\npackMode="graph";\n'.format(os.path.basename(fname)[:-4].replace('-','_')))
		fout.write('node [style="filled",fontname=Arial];\n')
		def twalker(t):
			tname = tokenNames[t.getType()]
			if tname == str(t):
				fout.write('"{0}" [shape=ellipse,label="{1}",fillcolor=paleturquoise];\n'.format(
					id(t),
					self._escape_dot_label(t)
					)
				)
			else:
				fout.write('"{0}" [shape=record,label="{{{2}|{1}}}",fillcolor=palegreen];\n'.format(
					id(t),
					self._escape_dot_label(t),
					self._escape_dot_label(tname)
					)
				)

			if t.parent is not None:
				fout.write('"{0}" -> "{1}";\n'.format(id(t.parent), id(t)))

			for ch in t.children:
				twalker(ch)

		twalker(result.tree)

		fout.write("}\n")