|
6 | 6 | import json |
7 | 7 | import unittest |
8 | 8 | import sys |
| 9 | +from contextlib import redirect_stdout |
9 | 10 | from io import StringIO |
10 | | - |
11 | 11 | from wikibot.wikiclient import WikiClient |
12 | 12 | from tests.test_WikiUser import TestWikiUser |
13 | 13 | from wikibot.wikipush import WikiPush, mainQuery |
14 | 14 | from tests.basetest import BaseTest |
15 | 15 |
|
| 16 | + |
16 | 17 | class TestWikiQuery(BaseTest): |
17 | 18 | ''' |
18 | 19 | tests for https://github.com/WolfgangFahl/py-3rdparty-mediawiki/issues/56 |
19 | 20 | ''' |
20 | | - def setUp(self): |
21 | | - BaseTest.setUp(self) |
| 21 | + |
| 22 | + def setUp(self, debug:bool=False, profile:bool=True): |
| 23 | + super().setUp(debug, profile) |
22 | 24 | self.eventQuery = "[[IsA::Event]][[Ordinal::>2]][[start date::>2018]][[start date::<2019]]| mainlabel = Event| ?Title = title| ?Event in series = series| ?_CDAT=creation date| ?_MDAT=modification date| ?ordinal=ordinal| ?Homepage = homepage|format=table" |
23 | | - pass |
| 25 | + self.getWikiUser("orcopy") |
| 26 | + self.getWikiUser("orclone") |
24 | 27 |
|
25 | 28 | def getWikiClient(self,wikiId='orcopy'): |
26 | 29 | ''' get the alternative SMW access instances for the given wiki id |
@@ -60,39 +63,42 @@ def testWikiQuery(self): |
60 | 63 |
|
61 | 64 | def testJsonDefalt(self): |
62 | 65 | """Test if default entityName is set correctly for format json""" |
63 | | - if self.inPublicCI(): return |
64 | 66 | argv=["-s","orcopy","-q",self.eventQuery] |
65 | 67 | mystdout = StringIO() |
66 | | - sys.stdout = mystdout |
67 | | - mainQuery(argv) |
| 68 | + with redirect_stdout(mystdout): |
| 69 | + mainQuery(argv) |
68 | 70 | res = mystdout.getvalue() |
| 71 | + if self.debug: |
| 72 | + print(res) |
69 | 73 | self.assertTrue("data" in json.loads(res).keys()) |
70 | 74 | return |
71 | 75 |
|
72 | 76 | def testJson(self): |
73 | 77 | """Test if given entityName is set correctly for format json""" |
74 | | - if self.inPublicCI(): return |
75 | 78 | entityName = "Event" |
76 | 79 | argv=["-s","orcopy","-q",self.eventQuery, "--entityName", entityName, "--format", "json"] |
77 | 80 | mystdout = StringIO() |
78 | | - sys.stdout = mystdout |
79 | | - mainQuery(argv) |
| 81 | + with redirect_stdout(mystdout): |
| 82 | + mainQuery(argv) |
80 | 83 | res = mystdout.getvalue() |
| 84 | + if self.debug: |
| 85 | + print(res) |
81 | 86 | self.assertTrue(entityName in json.loads(res).keys()) |
82 | 87 | return |
83 | 88 |
|
84 | 89 | def testCSV(self): |
85 | 90 | ''' |
86 | 91 | Test if wikiquery returns CSV format correctly |
87 | 92 | ''' |
88 | | - if self.inPublicCI(): return |
89 | 93 | entityName = "Event" |
90 | 94 | argv=["-s","orclone","-q",self.eventQuery, "--format", "csv"] |
91 | 95 | mystdout = StringIO() |
92 | | - sys.stdout = mystdout |
93 | | - mainQuery(argv) |
| 96 | + with redirect_stdout(mystdout): |
| 97 | + mainQuery(argv) |
94 | 98 | res = mystdout.getvalue() |
95 | | - expected_headline = "Event;title;series;creation_date;modification_date;ordinal;homepage\n" |
| 99 | + if self.debug: |
| 100 | + print(res) |
| 101 | + expected_headline = "Event;title;series;creation date;modification date;ordinal;homepage\n" |
96 | 102 | self.assertTrue(res.startswith(expected_headline)) |
97 | 103 | return |
98 | 104 |
|
|
0 commit comments