Mercurial > moin > extensions
annotate data/plugin/macro/_tests/test_DictColumns.py @ 512:31e327c450ca
PEP8 whitespace fix
HG : Enter commit message. Lines beginning with 'HG:' are removed.
author  Reimar Bauer <rb.proj AT googlemail DOT com> 

date  Mon, 22 Mar 2010 00:38:06 +0100 
parents  ef1f74bf4776 
children  946737f9eb1b 
rev  line source 

506
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

1 # * coding: iso88591 * 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

2 """ 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

3 MoinMoin  MoinMoin.macro DictColumns tests 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

4 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

5 @copyright: 2010 MoinMoin:ReimarBauer 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

6 @license: GNU GPL, see COPYING for details. 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

7 """ 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

8 import py 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

9 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

10 from MoinMoin._tests import become_trusted, create_page, make_macro, nuke_page 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

11 from MoinMoin.macro.DictColumns import _name2index, _csv2list, DictColumns 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

12 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

13 class TestDictColumns(object): 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

14 """ setup of common vars for testing of DictColumns """ 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

15 pagename = "DictColumns" 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

16 template_page = "BooksTemplate" 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

17 alias_page = "BookAlias" 
511
ef1f74bf4776
macro DictColumns: new keyword markup defined (default is "definition list"). By setting it to "title" the column headings are defined by the titles of the pageThe text below a title becomes assigned to the column.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
510
diff
changeset

18 title_page = "BookTitleExample" 
506
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

19 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

20 page_dict = [{"book": "Gray Hat Python: Python Programming for Hackers and Reverse Engineers", 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

21 "author": "Justin Seitz", 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

22 "language": "english", 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

23 "prize": "17.00", 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

24 "in stock": "31", 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

25 }, 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

26 {"book": "Python Cookbook", 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

27 "author": "Alex Martelli", 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

28 "language": "english", 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

29 "prize": "21.00", 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

30 "in stock": "37", 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

31 }, 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

32 {"book": "High Performance Python", 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

33 "author": "Anthony Lewis, Andrew Lewis, and Lewis Andrew", 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

34 "language": "english", 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

35 "prize": "24.90", 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

36 "in stock": "70", 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

37 }, 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

38 {"book": "Einstieg in Python 3", 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

39 "author": "Thomas Theis", 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

40 "language": "german", 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

41 "prize": "24.90", 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

42 "in stock": "20", 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

43 }, 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

44 {"book": "Hacking mit Python: Fehlersuche, Programmanalyse, Reverse Engineering", 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

45 "author": "Justin Seitz", 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

46 "language": "german", 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

47 "prize": "33.00", 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

48 "in stock": "70", 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

49 }] 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

50 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

51 text = """\ 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

52 book:: %(book)s 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

53 author:: %(author)s 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

54 language:: %(language)s 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

55 prize:: %(prize)s 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

56 in stock:: %(in stock)s 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

57 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

58  
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

59 CategoryTest%(language)s 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

60 """ 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

61 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

62 template_dict = {"book": "", "author": "", 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

63 "prize": "", "in stock": "", "publisher": ""} 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

64 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

65 template_text = """\ 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

66 book:: %(book)s 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

67 author:: %(author)s 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

68 prize:: %(prize)s 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

69 in stock:: %(in stock)s 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

70 publisher:: %(publisher)s 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

71 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

72  
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

73 CategoryTest 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

74 """ 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

75 alias_text = " prize:: %(prize)s" 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

76 alias_dict = {"prize": "prize (euro)"} 
512
31e327c450ca
PEP8 whitespace fix
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
511
diff
changeset

77 
511
ef1f74bf4776
macro DictColumns: new keyword markup defined (default is "definition list"). By setting it to "title" the column headings are defined by the titles of the pageThe text below a title becomes assigned to the column.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
510
diff
changeset

78 title_text = """\ 
ef1f74bf4776
macro DictColumns: new keyword markup defined (default is "definition list"). By setting it to "title" the column headings are defined by the titles of the pageThe text below a title becomes assigned to the column.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
510
diff
changeset

79 = book = 
ef1f74bf4776
macro DictColumns: new keyword markup defined (default is "definition list"). By setting it to "title" the column headings are defined by the titles of the pageThe text below a title becomes assigned to the column.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
510
diff
changeset

80 book example 
ef1f74bf4776
macro DictColumns: new keyword markup defined (default is "definition list"). By setting it to "title" the column headings are defined by the titles of the pageThe text below a title becomes assigned to the column.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
510
diff
changeset

81 = author = 
ef1f74bf4776
macro DictColumns: new keyword markup defined (default is "definition list"). By setting it to "title" the column headings are defined by the titles of the pageThe text below a title becomes assigned to the column.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
510
diff
changeset

82 author example 
ef1f74bf4776
macro DictColumns: new keyword markup defined (default is "definition list"). By setting it to "title" the column headings are defined by the titles of the pageThe text below a title becomes assigned to the column.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
510
diff
changeset

83 = prize = 
ef1f74bf4776
macro DictColumns: new keyword markup defined (default is "definition list"). By setting it to "title" the column headings are defined by the titles of the pageThe text below a title becomes assigned to the column.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
510
diff
changeset

84 prize example 
ef1f74bf4776
macro DictColumns: new keyword markup defined (default is "definition list"). By setting it to "title" the column headings are defined by the titles of the pageThe text below a title becomes assigned to the column.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
510
diff
changeset

85 = in stock = 
ef1f74bf4776
macro DictColumns: new keyword markup defined (default is "definition list"). By setting it to "title" the column headings are defined by the titles of the pageThe text below a title becomes assigned to the column.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
510
diff
changeset

86 in stock example 
ef1f74bf4776
macro DictColumns: new keyword markup defined (default is "definition list"). By setting it to "title" the column headings are defined by the titles of the pageThe text below a title becomes assigned to the column.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
510
diff
changeset

87 """ 
ef1f74bf4776
macro DictColumns: new keyword markup defined (default is "definition list"). By setting it to "title" the column headings are defined by the titles of the pageThe text below a title becomes assigned to the column.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
510
diff
changeset

88 
506
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

89 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

90 def setup_class(self): 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

91 """ initializes content """ 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

92 become_trusted(self.request) 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

93 template_text = self.template_text % self.template_dict 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

94 template_page = create_page(self.request, self.template_page, template_text) 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

95 alias_text = self.alias_text % self.alias_dict 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

96 alias_page = create_page(self.request, self.alias_page, alias_text) 
511
ef1f74bf4776
macro DictColumns: new keyword markup defined (default is "definition list"). By setting it to "title" the column headings are defined by the titles of the pageThe text below a title becomes assigned to the column.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
510
diff
changeset

97 title_page = create_page(self.request, self.title_page, self.title_text) 
506
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

98 for content in self.page_dict: 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

99 pagename = self.pagename + '/' + content["book"] 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

100 examples = create_page(self.request, pagename, self.text % content) 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

101 self.page = create_page(self.request, self.pagename, u'<<DictColumns>>') 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

102 self.macro = make_macro(self.request, self.page) 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

103 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

104 def teardown_class(self): 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

105 """ cleans everything """ 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

106 for content in self.page_dict: 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

107 pagename = self.pagename + '/' + content["book"] 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

108 nuke_page(self.request, pagename) 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

109 nuke_page(self.request, self.pagename) 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

110 nuke_page(self.request, self.template_page) 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

111 nuke_page(self.request, self.alias_page) 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

112 
511
ef1f74bf4776
macro DictColumns: new keyword markup defined (default is "definition list"). By setting it to "title" the column headings are defined by the titles of the pageThe text below a title becomes assigned to the column.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
510
diff
changeset

113 def test_get_dict(self): 
ef1f74bf4776
macro DictColumns: new keyword markup defined (default is "definition list"). By setting it to "title" the column headings are defined by the titles of the pageThe text below a title becomes assigned to the column.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
510
diff
changeset

114 dict_columns = DictColumns(self.macro, pagename=self.pagename, markup="title") 
ef1f74bf4776
macro DictColumns: new keyword markup defined (default is "definition list"). By setting it to "title" the column headings are defined by the titles of the pageThe text below a title becomes assigned to the column.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
510
diff
changeset

115 result = dict_columns.get_dict(self.title_page) 
ef1f74bf4776
macro DictColumns: new keyword markup defined (default is "definition list"). By setting it to "title" the column headings are defined by the titles of the pageThe text below a title becomes assigned to the column.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
510
diff
changeset

116 expected_result = {u'author': u'author example', 
ef1f74bf4776
macro DictColumns: new keyword markup defined (default is "definition list"). By setting it to "title" the column headings are defined by the titles of the pageThe text below a title becomes assigned to the column.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
510
diff
changeset

117 u'book': u'book example', 
ef1f74bf4776
macro DictColumns: new keyword markup defined (default is "definition list"). By setting it to "title" the column headings are defined by the titles of the pageThe text below a title becomes assigned to the column.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
510
diff
changeset

118 u'in stock': u'in stock example', 
ef1f74bf4776
macro DictColumns: new keyword markup defined (default is "definition list"). By setting it to "title" the column headings are defined by the titles of the pageThe text below a title becomes assigned to the column.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
510
diff
changeset

119 u'prize': u'prize example'} 
ef1f74bf4776
macro DictColumns: new keyword markup defined (default is "definition list"). By setting it to "title" the column headings are defined by the titles of the pageThe text below a title becomes assigned to the column.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
510
diff
changeset

120 assert result == expected_result 
ef1f74bf4776
macro DictColumns: new keyword markup defined (default is "definition list"). By setting it to "title" the column headings are defined by the titles of the pageThe text below a title becomes assigned to the column.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
510
diff
changeset

121 
506
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

122 def test_get_page_list(self): 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

123 """ tests selection of pages by the default regex search_term """ 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

124 result = DictColumns(self.macro, pagename=self.pagename).get_page_list() 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

125 expected_result = [self.pagename + '/' + content["book"] for content in self.page_dict] 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

126 # needs to have same length 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

127 assert len(result) == len(expected_result) 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

128 # needs to have same elements (order is independent) 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

129 assert set(result) == set(expected_result) 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

130 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

131 def test_get_page_list_default_pagename(self): 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

132 """ tests selection of pages by the default regex search_term and default pagename """ 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

133 result = DictColumns(self.macro).get_page_list() 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

134 expected_result = [self.pagename + '/' + content["book"] for content in self.page_dict] 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

135 # needs to have same length 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

136 assert len(result) == len(expected_result) 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

137 # needs to have same elements (order is independent) 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

138 assert set(result) == set(expected_result) 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

139 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

140 def test_get_page_list_search_term(self): 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

141 """ tests selection of pages by a search term of a category """ 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

142 # we search for search_term="category::CategoryTestgerman" 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

143 result = DictColumns(self.macro, search_term="category:CategoryTestgerman").get_page_list() 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

144 assert result is not None 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

145 expected_result = [self.pagename + '/' + content["book"] for content in self.page_dict 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

146 if content["language"] == "german"] 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

147 # needs to have same length 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

148 assert len(result) == len(expected_result) 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

149 # needs to have same elements (order is independent) 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

150 assert set(result) == set(expected_result) 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

151 # we search for search_term="category:CategoryTestenglish" 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

152 result = DictColumns(self.macro, search_term="category:CategoryTestenglish").get_page_list() 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

153 assert result is not None 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

154 expected_result = [self.pagename + '/' + content["book"] for content in self.page_dict 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

155 if content["language"] == "english"] 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

156 # needs to have same length 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

157 assert len(result) == len(expected_result) 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

158 # needs to have same elements (order is independent) 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

159 assert set(result) == set(expected_result) 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

160 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

161 def test_get_column_names_by_name(self): 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

162 """ tests used column names based on given name list """ 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

163 selected_pages = DictColumns(self.macro, pagename=self.pagename).get_page_list() 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

164 names = ['book', 'prize'] 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

165 result = DictColumns(self.macro, pagename=self.pagename, names=names).get_names(selected_pages) 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

166 # needs to have same length 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

167 assert len(result) == len(names) 
510
6318c91263c6
test_DictColumns: column_names_by_name checks now order too
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
506
diff
changeset

168 # needs to have same elements and order 
6318c91263c6
test_DictColumns: column_names_by_name checks now order too
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
506
diff
changeset

169 assert result == names 
506
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

170 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

171 def test_get_column_names_from_all_pages(self): 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

172 """ tests used column names based on all pages (page_dict) """ 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

173 selected_pages = DictColumns(self.macro, pagename=self.pagename).get_page_list() 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

174 # template_page has an additional key and one other is missing 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

175 selected_pages.append(self.template_page) 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

176 result = DictColumns(self.macro, pagename=self.pagename).get_names(selected_pages) 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

177 # we have different and duplicated names on both list, we need unique names for the test 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

178 expected_result = set(list(self.page_dict[0]) + list(self.template_dict)) 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

179 # needs to have same length 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

180 assert len(result) == len(expected_result) 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

181 # needs to have same elements (order is independent) 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

182 assert set(result) == set(expected_result) 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

183 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

184 def test_get_column_names_from_template_page(self): 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

185 """ tests used column names based on a template page (template_dict)""" 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

186 # you can use very different template pages for presenting the result 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

187 # also for creating the dict pages they are usefull too 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

188 selected_pages = DictColumns(self.macro, pagename=self.pagename).get_page_list() 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

189 result = DictColumns(self.macro, pagename=self.pagename, 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

190 template_page=self.template_page).get_names(selected_pages) 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

191 expected_result = list(self.template_dict) 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

192 # needs to have same length 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

193 assert len(result) == len(expected_result) 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

194 # needs to have same elements (order is independent) 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

195 assert set(result) == set(expected_result) 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

196 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

197 def test_dataset_all_names(self): 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

198 """ tests dataset for all keys (names) given from pages """ 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

199 selected_pages = DictColumns(self.macro, pagename=self.pagename).get_page_list() 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

200 names = DictColumns(self.macro, pagename=self.pagename).get_names(selected_pages) 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

201 result = DictColumns(self.macro, pagename=self.pagename).dataset(names, selected_pages) 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

202 # if something is broken we have no data but we can have result.columns 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

203 data = result.data 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

204 assert data != [] 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

205 # we need as much lines in result as we have in self.page_dict 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

206 assert len(result) == len(self.page_dict) 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

207 # columns are independent from table data. 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

208 assert result.columns[0].name == 'DictColumns' 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

209 assert result.columns[0].label == 'DictColumns' 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

210 # on default nothing is hidden 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

211 for idx in range(len(result.columns)): 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

212 assert result.columns[idx].hidden == 0 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

213 # check for author entry 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

214 idx_author = names.index('author') + 1 # offset because of pagename in first column 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

215 # check that this is the right entry in result.columns too 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

216 assert result.columns[idx_author].name == 'author' 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

217 # all authors from the page dict as reference 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

218 author_list = [self.page_dict[ix]['author'] for ix in range(len(self.page_dict))] 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

219 # we check every row for some entries 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

220 for row in data: 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

221 # line of data should have the length of names + 1 (for 'DictColumns' name) 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

222 assert len(row) == len(names) + 1 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

223 # check if the author is in the list 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

224 assert row[idx_author][1] in author_list 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

225 # check for pagename in alias of href 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

226 test_string = selected_pages[data.index(row)].split('/', 1)[1] 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

227 assert test_string in row[0] 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

228 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

229 def test_dataset_some_names(self): 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

230 """ tests setting of some names """ 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

231 selected_pages = DictColumns(self.macro, pagename=self.pagename).get_page_list() 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

232 names = ['author', 'language', 'prize'] 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

233 result = DictColumns(self.macro, pagename=self.pagename).dataset(names, selected_pages) 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

234 data = result.data 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

235 # if something is broken we have no data but we can have result.columns 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

236 assert data != [] 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

237 assert len(result) == len(self.page_dict) 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

238 # needs to have same length 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

239 assert len(result.columns) == len(names) + 1 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

240 for name in names: 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

241 idx = names.index(name) + 1 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

242 assert result.columns[idx].name == name 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

243 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

244 def test_dataset_filter_name(self): 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

245 """ tests filtering of output by a given key value pair """ 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

246 selected_pages = DictColumns(self.macro, pagename=self.pagename).get_page_list() 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

247 names = ["book", "author", "language", "prize"] 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

248 # filters for this condition 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

249 filter_name = ["prize", "language"] 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

250 hidden_columns = ["book", "language"] 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

251 result = DictColumns(self.macro, pagename=self.pagename, hide=hidden_columns, filter_name=filter_name).dataset(names, selected_pages) 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

252 # if something is broken we have no data but we can have result.columns 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

253 data = result.data 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

254 assert data != [] 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

255 # we insert the self.pagename at position 0 because this makes comparison easier 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

256 names.insert(0, self.pagename) 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

257 for idx in range(len(result.columns)): 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

258 if names[idx] in filter_name: 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

259 assert result.columns[idx].name in filter_name 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

260 assert result.columns[idx].autofilter == 1 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

261 else: 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

262 assert result.columns[idx].name in set(names)  set(filter_name) 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

263 assert result.columns[idx].autofilter == 0 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

264 if names[idx] in hidden_columns: 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

265 assert result.columns[idx].name in hidden_columns 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

266 assert result.columns[idx].hidden == 1 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

267 else: 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

268 assert result.columns[idx].name in set(names)  set(hidden_columns) 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

269 assert result.columns[idx].hidden == 0 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

270 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

271 def test_dataset_filter_value(self): 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

272 """ tests filtering of output by a given key value pair """ 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

273 selected_pages = DictColumns(self.macro, pagename=self.pagename).get_page_list() 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

274 names = ['author', 'language', 'prize'] 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

275 # filters for this condition 
511
ef1f74bf4776
macro DictColumns: new keyword markup defined (default is "definition list"). By setting it to "title" the column headings are defined by the titles of the pageThe text below a title becomes assigned to the column.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
510
diff
changeset

276 filter_value = "prize=24.90" 
506
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

277 result = DictColumns(self.macro, pagename=self.pagename, filter_value=filter_value).dataset(names, selected_pages) 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

278 assert len(result.columns) == len(names) + 1 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

279 idx = names.index("prize") + 1 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

280 # if something is broken we have no data but we can have result.columns 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

281 data = result.data 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

282 assert data != [] 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

283 for row in data: 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

284 # there should be no other result 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

285 assert row[idx][1] == u"24.90" 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

286 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

287 def test_dataset_hide_names(self): 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

288 """ tests hiding columns from output """ 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

289 selected_pages = DictColumns(self.macro, pagename=self.pagename).get_page_list() 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

290 names = list(self.page_dict[0]) 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

291 hidden_columns = ["author", "language", "example"] 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

292 title = "example" 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

293 result = DictColumns(self.macro, pagename=self.pagename, 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

294 hide=hidden_columns, title=title).dataset(names, selected_pages) 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

295 # if something is broken we have no data but we can have result.columns 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

296 data = result.data 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

297 assert data != [] 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

298 # we insert the title at position 0 because this makes comparison easier 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

299 names.insert(0, title) 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

300 for idx in range(len(result.columns)): 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

301 if names[idx] in hidden_columns: 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

302 assert result.columns[idx].name in hidden_columns 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

303 assert result.columns[idx].hidden == 1 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

304 else: 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

305 assert result.columns[idx].name in set(names)  set(hidden_columns) 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

306 assert result.columns[idx].hidden == 0 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

307 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

308 def test_dataset_alias_page(self): 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

309 """ tests column header settings from an alias page """ 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

310 selected_pages = DictColumns(self.macro, pagename=self.pagename).get_page_list() 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

311 names = list(self.page_dict[0]) 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

312 result = DictColumns(self.macro, pagename=self.pagename, 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

313 alias_page=self.alias_page).dataset(names, selected_pages) 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

314 data = result.data 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

315 # if something is broken we have no data but we can have result.columns 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

316 assert data != [] 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

317 # get names from all columns 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

318 names = [result.columns[idx].name for idx in range(len(result.columns))] 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

319 # there should be nothing left over 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

320 assert set(self.alias_dict.values())  set(names) == set([]) 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

321 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

322 def test_render(self): 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

323 """ tests if the macro renders by default settings """ 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

324 result = DictColumns(self.macro, pagename=self.pagename).render() 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

325 # if there is a table generated we have much output 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

326 assert len(result) > 2000 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

327 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

328 def test_render_no_result(self): 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

329 """ tests for no result """ 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

330 result = DictColumns(self.macro, 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

331 pagename="I'am pretty sure this does never exist").render() 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

332 # if there is not a table generated we get a hint what is wrong 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

333 assert len(result) < 200 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

334 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

335 class TestDictColumns_name2index(object): 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

336 def test_name2index(self): 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

337 """ tests index of selected names in names """ 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

338 names = ['A', 'B', 'C', 'D', 'E', ] 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

339 selected_names = ['E', 'A', 'B'] 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

340 result = _name2index(names, selected_names) 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

341 assert result == [4, 0, 1] 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

342 # tests wrong selection (name not in names) 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

343 selected_names = ['E', 'A', 'B', 'G'] 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

344 result = _name2index(names, selected_names) 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

345 assert result == [] 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

346 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

347 class TestDictColumns_csv2list(object): 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

348 def test_csv2list(self): 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

349 """ tests conversion from csv input to list value """ 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

350 text = "A, B,C ,D, E," 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

351 result = _csv2list(text) 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

352 expected_result = ['A', 'B', 'C', 'D', 'E'] 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

353 assert result == expected_result 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

354 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

355 coverage_modules = ['MoinMoin.macro.DictColumns'] 
b7a9843c5730
macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

356 