def test_2(): # Test parsing to Node # that the line lineindex are correct # They start from 0, since enumerate() generates them, # It seemed inconsistent to change them to start from 1. # Which will be made in error prints. from guppy import Root dt = Root().guppy.gsl.DottedTree parse = dt.parse_string unparse = dt.unparse_node node = parse("""\ line 0 .line 1 ..line 2 line 3 .line 4 """) exp = Node('line 0', ( Node('line 1', (Node('line 2\nline 3', (), 2),), 1), Node('line 4\n', (), 4)), 0) assert repr(node) == repr(exp) print node
def test_string(s=None, name=None): from guppy import Root gsl = Root().guppy.gsl me = gsl.Text if s is None: s = getattr(me._parent.test.testdata, name) T = me.Tkinter node = me.node_of_string(s, nostrip=1) me._parent.Html.node2file(node, '/tmp/x.html') t = RecordingInter() me.node2inter(node, t) import cPickle as pickle t.prepare_for_pickle() root = T.Tk() root.withdraw() text = me._root.guppy.etc.textView.TextViewer(root, 'test', data='').textView text['state'] = 'normal' text['font'] = 'Times -12' text.bind('<Destroy>', lambda event: root.quit()) ti = TextInter(me, text) t.play(ti) text.mainloop()
def __init__(self): self.nrefs = {} from guppy import Root self.R = R = Root() self.V = R.guppy.heapy.View self.P = R.guppy.heapy.Path self.xmemstats = R.guppy.heapy.heapyc.xmemstats
def test_main(debug=0): from guppy import Root gsl = Root().guppy.gsl gsl.Document._test_main_() gsl.DottedTree.test_main() gsl.FileIO.set_test_mode() gsl.Filer._test_main_() gsl.Gsml._test_main_() gsl.Main._test_main_() gsl.SpecNodes.test_main()
def setUp(self): from guppy import Root self.python = Root() self.guppy = self.python.guppy self.heapy = self.guppy.heapy self.Part = self.heapy.Part self.ImpSet = self.heapy.ImpSet self.Use = self.heapy.Use self.View = self.heapy.View self.iso = self.Use.iso self.idset = self.Use.idset
def setUp(self): from guppy import Root self.python = Root() self.guppy = self.python.guppy self.heapy = self.guppy.heapy self.Part = self.heapy.Part self.ImpSet = self.heapy.ImpSet self.Use = self.heapy.Use self.View = self.heapy.View self.allocation_behaves_as_originally = self.heapy.allocation_behaves_as_originally self.iso = self.Use.iso self.idset = self.Use.idset
def test_1(): # Test parsing to sexpr's and back # for a variety of cases from guppy import Root dt = Root().guppy.gsl.DottedTree dt.node = dt.node_sexpr parse = dt.parse_string unparse = dt.unparse_sexpr for x, y in [ ['', ('',)], ['a', ('a',)], ['.a', ('',('a',))], ['a\n.b', ('a',('b',))], ['a\nb\n.c', ('a\nb',('c',))], ["""\n.a\n..a""", ('\n', ('a', ('a',)))], ["""hello\n.a\n.b\n..ba\nx\n..bb""", ('hello', ('a',), ('b', ('ba\nx',), ('bb',)))], # Quoting dots [r'\.', ('.',)], [r'.\.', ('',('.',))], # Preserving quote ['\\', ('\\',)], ['.\n\\', ('', ('\n\\',))], # Quoting quote-dots [r'\\.', (r'\.',)], # Preserving whitespace starting a tag # Or should it be stripped? I think better not, it would complicate transparency. [r'. tag', ('',(' tag', ))], # Preserving initial whitespace [' ', (' ',)], # Preserving initial newline ['\n', ('\n',)], ['\na', ('\na',)], # A n intended usage example [''' initial text .aspect for guppy.hsp ..returns ...type A ...latex ~\\ \..~|begincolorbox|~raw::~LaTeX~\\ ~\\ ~~~{\textbackslash}{\textbackslash}begin{\{}center{\}}~\\ .aspect for guppy.gsl ..contains DottedTree ''', ('\ninitial\ntext', ('aspect for guppy.hsp', ('returns', ('type A',), ('latex\n~\\\n..~|begincolorbox|~raw::~LaTeX~\\\n~\\\n~~~{\textbackslash}{\textbackslash}begin{\\{}center{\\}}~\\',))), ('aspect for guppy.gsl', ('contains DottedTree\n',)))] ]: z = parse(x) if y is not None: assert z == y assert unparse(z).strip() == x.strip() # Unparsing x and then parsing should give back x transparently # for any tree x, involving any combination of dots, quotes and other characters. # List of special chars and one normal chars = [dt.quotechar, dt.dotchar, '\n', ' ', 'a'] import random ## # Generate a random node with random number of children. # Shuffles the chars list to make the tag string. # @param maxchild maximum number of children def randnode(maxchild): numchild = random.randint(0, maxchild) random.shuffle(chars) tag = ''.join(chars) children = [randnode(maxchild-1) for i in range(numchild)] return dt.node(tag, children, 0) for i in range(10): y = randnode(3) x = unparse(y) z = parse(x) assert z == y
def test_main(): from guppy import Root root = Root() root.guppy.gsl.SpecNodes.main()
p.close() if p.stack: raise SyntaxError, 'Missing end tag' node = self.node_of_taci('block', '', p.out, 0) return node def _test_main_(self): x = """ <!DOCTYPE html...> This is an <em> emphasized </em> word. See also <a href="guppy-pe.sf.net"> Guppy. </a> Defined as <use_my_macro/>. Handle char ref: d. Handle char ref: <. <!-- A comment --> <?A processing instruction> <namespace:tag /> """ node = self.node_of_gsml(x) print node if 0 or __name__ == '__main__': from guppy import Root Root().guppy.gsl.Gsml._test_main_()
def __init__(self, mod): self.mod = mod def get_subject(self, name): return TestSubject(self.mod, name) env = TestEnv(self) x = """ .h1: Description of subject ..em ...use: A .h1: Reversing arguments .use: reverse ..text: A ..text: B ..text: C """ node = self._parent.SpecNodes.node_of_string(x) y = self.document(node, env) r = y.get_result() print r h = self._parent.Html.doc2html(r) print h open('/tmp/d.html','w').write(h) if 0 or __name__=='__main__': from guppy import Root Root().guppy.gsl.Document._test_main_()
X = ''' .write file: %s %s .write file: %s ..text %s ..end '''%(tempname, data2, tempname+'.3', data3) node = N.node_of_string(X) f = self.filer(node) f.write() assert IO.read_file(tempname+self.backup_suffix) == data d = IO.read_file(tempname) assert d == data2 assert IO.read_file(tempname+'.3') == data3 finally: for name in IO.listdir(tempdir): IO.remove(IO.path.join(tempdir, name)) IO.rmdir(tempdir) if 0 or __name__=='__main__': # doesnt work from guppy import Root gsl = Root().guppy.gsl gsl.FileIO.set_test_mode() gsl.Filer._test_main_()