示例#1
0
    def testPlantUML(self):
        if not getpass.getuser() == "travis":
            wikibot = WikiBot.ofWikiId("rq")
            smw = SMW(wikibot.site)
            ask = """{{#ask: [[Concept:SchemaProperty]][[SchemaProperty schema::ConfIDentSchema]]
|mainlabel=SchemaProperty
| ?SchemaProperty parent = parent
| ?SchemaProperty cardinality = cardinality
| ?SchemaProperty kind = kind
| ?SchemaProperty definition = definition
| ?SchemaProperty comment = comment 
| ?SchemaProperty allowedValue = allowedValue
| ?SchemaProperty examples = examples
| ?SchemaProperty name = name
| ?SchemaProperty type = type
| ?SchemaProperty mapsTo = mapsTo
| ?SchemaProperty id = id
| ?SchemaProperty schema = schema
|sort=SchemaProperty kind,SchemaProperty name
|order=ascending,ascending
| limit=200 
}}"""
            result = smw.query(ask)
            if TestPlantUML.debug:
                print(result)
            pu = PlantUML("http://rq.bitplan.com/index.php")
            pu.generate(result)
示例#2
0
    def test_ask(self):
        """ test using the SMW ask API """
        if not getpass.getuser() == "travis":
            wikibot = WikiBot.ofWikiId("rq")
            smw = SMW(wikibot.site)
            ask = """{{#ask: [[Concept:SchemaProperty]][[SchemaProperty schema::ConfIDentSchema]]
|mainlabel=SchemaProperty
| ?SchemaProperty parent = parent
| ?SchemaProperty cardinality = cardinality
| ?SchemaProperty kind = kind
| ?SchemaProperty definition = definition
| ?SchemaProperty comment = comment 
| ?SchemaProperty allowedValue = allowedValue
| ?SchemaProperty examples = examples
| ?SchemaProperty name = name
| ?SchemaProperty type = type
| ?SchemaProperty mapsTo = mapsTo
| ?SchemaProperty id = id
| ?SchemaProperty schema = schema
|sort=SchemaProperty kind,SchemaProperty name
|order=ascending,ascending
| limit=200 
}}"""
            result = smw.query(ask)
            if TestWikiAccess.debug:
                print(result)
 def testGetConcept(self):
     """ test extracting a concept from an ask query"""
     smw = SMW()
     fixedAsk = smw.fixAsk(TestSMW.testask1)
     concept = smw.getConcept(fixedAsk)
     if self.debug:
         print(concept)
     self.assertEqual(concept, "Semantic_MediaWiki_Cons_2012")
 def testFixAsk(self):
     """ test fixing an ask query to be made fit for API use"""
     smw = SMW()
     fixedAsk = smw.fixAsk(TestSMW.testask1)
     expected = """[[Concept:Semantic_MediaWiki_Cons_2012]]|?Has_Wikidata_item_ID=WikiDataId|?Has_planned_finish=finish|?Has_planned_start=start|?Has_location=location|format=table"""
     if self.debug:
         print(fixedAsk)
     self.assertEqual(expected, fixedAsk)
 def _raw_api_side_effect_with_oversized_result(action, http_method, *args, **kwargs):
     query = kwargs["query"]
     offset = SMW.getOuterMostArgumentValueOfQuery("offset", query)
     n = int(int(offset)/RESULTS_PER_RESPONSE)+1
     res = self.result_of(n)
     res["query-continue-offset"] = RESULTS_PER_RESPONSE*n if n < MAX/RESULTS_PER_RESPONSE else 0
     return res
 def testArgumentValueExtraction(self):
     """ test if the argument value is correctly extracted from a given query"""
     # Test extraction
     expected = 12
     self.assertEqual(
         SMW.getOuterMostArgumentValueOfQuery(
             "limit", "[[Category:Person]]|limit=12"), expected,
         "Unable to extract the argument")
     self.assertEqual(
         SMW.getOuterMostArgumentValueOfQuery(
             "limit", "[[Category:Person]]|LIMIT=12"), expected,
         "Unable to extract the argument written as 'LIMIT' (Extraction should not be case sensitive)"
     )
     self.assertEqual(
         SMW.getOuterMostArgumentValueOfQuery(
             "limit", "[[Category:Person]]|LiMiT=12"), expected,
         "Unable to extract the argument written as 'LiMiT' (Extraction should not be case sensitive)"
     )
     self.assertEqual(
         SMW.getOuterMostArgumentValueOfQuery(
             "limit", "[[Category:Person]] | limit = 12"), expected,
         "Unable to extract the argument")
     self.assertEqual(
         SMW.getOuterMostArgumentValueOfQuery(
             "limit", "[[Category:Person]]|  limit=  12"), expected,
         "Unable to extract the argument")
     self.assertEqual(
         SMW.getOuterMostArgumentValueOfQuery(
             "limit", "[[Category:Person]]|limit   =12"), expected,
         "Unable to extract the argument")
     self.assertEqual(
         SMW.getOuterMostArgumentValueOfQuery("arg", "[[arg = 1]]|arg=12"),
         expected, "Incorrect extraction of arg")
     expected = 7
     self.assertEqual(
         SMW.getOuterMostArgumentValueOfQuery(
             "arg", "[[Category:Person]]|offset=12 | arg=7 | limit=5"),
         expected, "Unable to detect arg if other arguments are present")
     self.assertEqual(
         SMW.getOuterMostArgumentValueOfQuery(
             "arg", "[[Category:Person]]|arg=12 | arg=7 | limit=5"),
         expected, "Unable to detect last occurring argument arg correctly")
     # Test handling of invalid input
     self.assertEqual(
         SMW.getOuterMostArgumentValueOfQuery("arg",
                                              "[[Category:Person]]"), None,
         "Incorrect response to query without the argument. None should be returned"
     )
     self.assertEqual(
         SMW.getOuterMostArgumentValueOfQuery(None,
                                              "[[Category:Person]]"), None,
         "Incorrect response to None as argument. None should be returned")
     self.assertEqual(
         SMW.getOuterMostArgumentValueOfQuery("",
                                              "[[Category:Person]]"), None,
         "Incorrect response to argument being an empty string. None should be returned"
     )
     self.assertEqual(
         SMW.getOuterMostArgumentValueOfQuery("args", "[[args=1]]"), None,
         "Argument should not be detected inside the page selection condition."
     )
     self.assertEqual(SMW.getOuterMostArgumentValueOfQuery("arg", ""), None,
                      "Incorrect response for empty query")
     self.assertEqual(SMW.getOuterMostArgumentValueOfQuery("arg",
                                                           None), None,
                      "Missing error handling for None as query input")
     # Test if decimal numbers as value lead to None (Only integers should be extracted)
     self.assertEqual(
         SMW.getOuterMostArgumentValueOfQuery(
             "arg", "[[Category:Person]]|arg=12.5"), None,
         "Decimal number was extracted as correct value. Only integers should be extracted."
     )