From c40f8d6a3431a55285bc8f48e6429ef58f84c2ca Mon Sep 17 00:00:00 2001 From: Alvin Wan Date: Fri, 17 Nov 2017 01:05:41 -0800 Subject: [PATCH] fixed tests --- tests/test_tex2py.py | 2 +- tex2py/tex2py.py | 9 ++++----- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/tests/test_tex2py.py b/tests/test_tex2py.py index 0a95381..65df411 100644 --- a/tests/test_tex2py.py +++ b/tests/test_tex2py.py @@ -20,7 +20,7 @@ def iscream(): def test_basic_prop(chikin): """tests that custom __getattr__ works""" - assert str(chikin) == '' + assert str(chikin) == '[document]' assert chikin.depth == 0 assert len(chikin.branches) == 2 assert isinstance(chikin.section, TreeOfContents) diff --git a/tex2py/tex2py.py b/tex2py/tex2py.py index 592d7e4..ddd83b0 100644 --- a/tex2py/tex2py.py +++ b/tex2py/tex2py.py @@ -1,7 +1,6 @@ from TexSoup import TexSoup, TexNode from pptree import print_tree - class TreeOfContents(object): """Tree abstraction for latex source""" @@ -142,9 +141,9 @@ def expandDescendants(self, branches=None): >>> toc = TOC.fromLatex(r'\section{h1}\subsection{subh1}\section{h2}\ ... \subsection{subh2}') >>> len(list(toc.source.descendants)) - 8 + 9 >>> len(toc.descendants) - 8 + 9 """ branches = branches or self.branches return sum([b.descendants for b in branches], []) + \ @@ -186,11 +185,11 @@ def __getattr__(self, attr, *default): return self.source return getattr(self.source, attr, *default) if attr in self.valid_tags: - return next(filter(lambda t: t.name == attr, self.branches), None) + return next(filter(lambda t: t.source.name == attr, self.branches), None) if len(default): return default[0] if attr[-1] == 's' and tag in self.valid_tags: - condition = lambda t: t.name == tag + condition = lambda t: t.source.name == tag return filter(condition, self.branches) raise AttributeError("'TreeOfContents' object has no attribute '%s'" % attr)