Пример #1
0
    def test_handle_type(self):
        """
        Unit test for :meth:`ZoteroIngest.handle_documentType`\.
        """
        ingester = ZoteroIngest(self.rdf_path)
        ingester.graph = self.g

        predicate, value = ingester.handle_documentType(ZOTERO.itemType, "!")
        self.assertEqual(
            predicate, "entity_type",
            "ZOTERO.itemType should be flagged as the Resource.entity_type")
Пример #2
0
    def test_handle_date(self):
        """
        Unit test for :meth:`ZoteroIngest.handle_date`\.
        """
        ingester = ZoteroIngest(self.rdf_path)
        ingester.graph = self.g

        predicate, value = ingester.handle_date(DC.date, self.date)
        self.assertIsInstance(
            value, datetime.datetime,
            "ISO-8601 compliant dates should be recast to datetime instances.")
Пример #3
0
 def test_handle_link(self):
     ingester = ZoteroIngest(self.rdf_path)
     ingester.graph = self.g
     predicate, values = ingester.handle_link(RSS.link, self.doc)
     values = dict(values)
     self.assertIn('url', values)
     self.assertEqual(
         values['url'], self.location,
         "The URI of the link target should be interpreted as an URL.")
     self.assertIsInstance(
         values[DCTERMS.dateSubmitted.toPython()], datetime.datetime,
         "dateSubmitted should be recast as a datetime object.")
Пример #4
0
    def test_get_resources_nodes(self):
        """
        Unit test for :meth:`ZoteroIngest._get_resources_nodes`\.
        """
        ingester = ZoteroIngest(self.rdf_path)
        nodes = ingester._get_resources_nodes(BIB.Article)
        self.assertIsInstance(
            nodes, types.GeneratorType,
            "_get_resources_nodes Should return a generator object that yields"
            " rdflib.BNodes.")

        nodes = [n for n in nodes]
        self.assertIsInstance(nodes[0], BNode)
        self.assertEqual(len(nodes), 1, "There should be one Article node.")
Пример #5
0
    def test_handle_identifier(self):
        """
        Unit test for :meth:`ZoteroIngest.handle_identifier`\.
        """
        ingester = ZoteroIngest(self.rdf_path)

        # We want to intervene on our original graph here.
        ingester.graph = self.g
        result = ingester.handle_identifier(DC.identifier, self.ident)
        self.assertIsInstance(result, tuple, "Handlers should return tuples.")
        self.assertEqual(
            result[0], 'uri',
            "DCTERMS.URI identifiers should be used as first-class URIs.")
        self.assertEqual(result[1].toPython(), self.test_uri)

        result = ingester.handle_identifier(DC.identifier, self.ident2)
        self.assertIsInstance(result, tuple, "Handlers should return tuples.")
        self.assertEqual(result[0], BIB.doi)
        self.assertEqual(result[1].toPython(), self.test_doi)
Пример #6
0
 def test_load_graph(self):
     """
     Unit test for :meth:`ZoteroIngest.__init__` with RDF document only.
     """
     ingester = ZoteroIngest(self.rdf_path)
     self.assertIsInstance(
         ingester.graph, Graph,
         "When a path to an RDF document is passed to the constructor, an"
         " rdflib.Graph should be instantiated and populated.")
     self.assertEqual(len(ingester.graph), 10,
                      "The Graph should be populated with 10 nodes.")
Пример #7
0
    def test_set_value(self):
        """
        Unit test for :meth:`ZoteroIngest._set_value`\.
        """
        ingester = ZoteroIngest(self.rdf_path)
        ingester._new_entry()
        ingester._set_value("key", "value")

        self.assertIn("key", ingester.data[-1],
                      "_set_value should add the key to the current entry.")
        self.assertEqual(ingester.data[-1]["key"], ["value"],
                         "_set_value should add the value to a list")
Пример #8
0
    def test_handle(self):
        """
        Unit test for :meth:`ZoteroIngest.handle`\.
        """
        ingester = ZoteroIngest(self.rdf_path)
        ingester.graph = self.g
        ingester._new_entry()  # Need somewhere to put the value.
        predicate, value = ingester.handle(DC.identifier, self.ident)
        self.assertEqual(
            value, self.test_uri,
            "handle() should pass along the predicate and value to"
            " handle_identifier(), and return native Python types.")

        predicate, value = ingester.handle(DC.nonsense, "value")
        self.assertEqual(
            predicate, DC.nonsense.toPython(),
            "If there are no special handlers for the predicate, it should be"
            " returned as a native Python type.")
        self.assertEqual(value, "value",
                         "So too with the corresponding value.")
Пример #9
0
    def test_parse_zotero_rdf(self):
        ingester = ZoteroIngest("test_data/TestRDF.rdf")

        data = ingester.next()
        self.assertIn('name', data)
        self.assertIn('entity_type', data)