def check(self, dirdata, file_tree, links, errors=[]): page_text = self.genedir(**dirdata) page_path = 'it does not depend on the page_path' web = MockWeb() DictTable = MockDictTable.new_mock(file_tree) glob_list = Mock(return_value=sorted(file_tree)) setup_wiki(web=web, DictTable=DictTable, glob_list=glob_list) with CaptureStdIO() as stdio: page_html = gene_html(page_text, page_path, _debug=True) stderr = stdio.read_stderr() for key in dirdata['data'].split(): td_tag = '<td>{0}</td>'.format(key) num_td = page_html.count(td_tag) num_data = len(filter(lambda d: key in d, file_tree.itervalues())) eq_( num_td, num_data, "there must be #{0} of '{2}'. #{1} exists".format( num_data, num_td, td_tag)) for link in links: assert '{0}</a>'.format(link) in page_html for error in errors: assert escape(error, True) in page_html assert error in stderr if not errors: assert not stderr
def check(self, page_text, file_tree, stats): page_path = 'it does not depend on the page_path' web = MockWeb() DictTable = MockDictTable.new_mock(file_tree) glob_list = Mock(return_value=sorted(file_tree)) setup_wiki(web=web, DictTable=DictTable, glob_list=glob_list) page_html = gene_html(page_text, page_path) for (key, val) in stats.iteritems(): eq_(page_html.count(key), val, "page_html must contains %d of '%s'" % (val, key))
def check(self, page_path, list_descendants): page_text = '.. list-pages::' web = MockWeb(list_descendants=list_descendants) DictTable = None # it will not be called glob_list = None # it will not be called setup_wiki(web=web, DictTable=DictTable, glob_list=glob_list) page_html = gene_html(page_text, page_path, _debug=True) web.list_descendants.assert_called_with(page_path) for subpage in list_descendants: assert subpage in page_html
def check(self, list_descendants): page_path = 'it does not depend on the page_path' page_text = ".. list-pages::" web = MockWeb(list_descendants=list_descendants) DictTable = object() # DictTable should not be used setup_wiki(web=web, DictTable=DictTable) page_html = gene_html(page_text, page_path) assert 'List of Pages' in page_html html_format = 'href="%(link)s">%(link)s</a>' for sub_link in list_descendants: html_str = html_format % {'link': sub_link} assert html_str in page_html
def check(self, dirdata, files): page_text = self.genedir(**dirdata) page_path = 'it does not depend on the page_path' web = MockWeb() DictTable = None # it will not be called glob_list = Mock(return_value=sorted(files)) setup_wiki(web=web, DictTable=DictTable, glob_list=glob_list) page_html = gene_html(page_text, page_path, _debug=True) datadir = web.app.config['DATADIRPATH'] base_syspath = os.path.join(datadir, dirdata.get('base', '')) glob_list.assert_called_with( map(lambda arg: os.path.join(base_syspath, arg), dirdata['args'])) eq_(page_html.count('<img'), len(files))
def check(self, page_text, file_tree, dictdiff, links): page_path = 'it does not depend on the page_path' web = MockWeb() DictTable = MockDictTable.new_mock(file_tree) glob_list = Mock(return_value=sorted(file_tree)) setup_wiki(web=web, DictTable=DictTable, glob_list=glob_list) page_html = gene_html(page_text, page_path) for key in dictdiff: assert key in page_html if links: for link in links: assert '%s</a>' % link in page_html elif links == []: assert 'link(s)' not in page_html
def test_gene_html_no_fail(): exception_message = ( '`gene_html` should not fail whatever happen during the ' 'html generation, provided DEBUG=False') page_text = trim(""" .. dictdiff:: * dictdiff is for raising Exception via DictTable """) page_path = 'it does not depend on the page_path' web = MockWeb() DictTable = Mock() DictTable.from_path_list = Mock( side_effect=CheckException(exception_message)) glob_list = Mock(return_value=[]) setup_wiki(web=web, DictTable=DictTable, glob_list=glob_list) # error must be suppressed when _debug=False page_html = gene_html(page_text, page_path, _debug=False) assert exception_message in page_html # TB will be returned # error must NOT be suppressed when _debug=True assert_raises(CheckException, gene_html, page_text, page_path, _debug=True)
def check(self, dirdata, file_tree, links, errors=[]): page_text = self.genedir(**dirdata) page_path = 'it does not depend on the page_path' web = MockWeb() DictTable = MockDictTable.new_mock(file_tree) glob_list = Mock(return_value=sorted(file_tree)) setup_wiki(web=web, DictTable=DictTable, glob_list=glob_list) with CaptureStdIO() as stdio: page_html = gene_html(page_text, page_path, _debug=True) stderr = stdio.read_stderr() for key in dirdata['data'].split(): td_tag = '<td>{0}</td>'.format(key) assert td_tag in page_html for link in links: assert '{0}</a>'.format(link) in page_html for error in errors: assert escape(error, True) in page_html assert error in stderr if not errors: assert not stderr