Fixing website and API documentation links
[PyCIM.git] / PyCIM / Test / RDFXMLReaderTest.py
blobbd5e1787c8b95fb419294d92e6ef44a09347ba3f
1 # Copyright (C) 2010-2011 Richard Lincoln
2 # Copyright (C) 2011 Stefan Scherfke
4 # Permission is hereby granted, free of charge, to any person obtaining a copy
5 # of this software and associated documentation files (the "Software"), to
6 # deal in the Software without restriction, including without limitation the
7 # rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
8 # sell copies of the Software, and to permit persons to whom the Software is
9 # furnished to do so, subject to the following conditions:
11 # The above copyright notice and this permission notice shall be included in
12 # all copies or substantial portions of the Software.
14 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
20 # IN THE SOFTWARE.
22 import io
23 import unittest
25 from os.path import dirname, join
27 from PyCIM import cimread, RDFXMLReader
29 from CIM15 import nsURI as nsURICIM15, packageMap as packageMapCIM15
30 from CIM15.CDPSM.Asset import packageMap as assetMap
31 from CIM15.CDPSM.Connectivity import packageMap as connMap
32 from CIM15.CDPSM.Balanced import packageMap as equipMap
33 from CIM15.CDPSM.Geographical import packageMap as geoMap
36 RDFXML_FILE = join(dirname(__file__), "Data", "EDF_AIGUE_v9_COMBINED.xml")
38 ASSET_FILE = join(dirname(__file__), "Data", "EDF_AIGUE_v9_ASSET.xml")
39 CONN_FILE = join(dirname(__file__), "Data", "EDF_AIGUE_v9_CONN.xml")
40 EQUIP_FILE = join(dirname(__file__), "Data", "EDF_AIGUE_v9_EQUIP.xml")
41 GEO_FILE = join(dirname(__file__), "Data", "EDF_AIGUE_v9_GEO.xml")
43 EMPTY_CIM = u'''<?xml version=\'1.0\'?>
44 <rdf:RDF xmlns:cim="http://iec.ch/TC57/2010/CIM-schema-cim15#"
45 xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" />'''
48 class RDFXMLReaderTestCase(unittest.TestCase):
49 """Test CIM RDF/XML parsing.
50 """
52 def testCombined(self):
53 """Test CIM RDF/XML parsing.
54 """
55 d = cimread(RDFXML_FILE)
57 self.assertEqual(len(d), 5894)
59 def test_cim_reads_are_independent(self):
60 cimread(ASSET_FILE, assetMap, nsURICIM15)
61 sio = io.StringIO(EMPTY_CIM)
62 empty_cim_dict = cimread(sio)
63 self.assertEqual(empty_cim_dict, {})
65 def testProfile(self):
66 d = {}
68 d.update(cimread(ASSET_FILE, assetMap, nsURICIM15))
69 d.update(cimread(CONN_FILE, connMap, nsURICIM15))
70 d.update(cimread(EQUIP_FILE, equipMap, nsURICIM15))
71 d.update(cimread(GEO_FILE, geoMap, nsURICIM15))
73 self.assertEqual(len(d), 5893)
75 def testGetNamespaces(self):
76 ns = RDFXMLReader.xmlns(RDFXML_FILE)
77 self.assertEqual(ns, {
78 'cim': 'http://iec.ch/TC57/2010/CIM-schema-cim15#',
79 'rdf': 'http://www.w3.org/1999/02/22-rdf-syntax-ns#',
82 self.assertEqual(RDFXMLReader.get_rdf_ns(ns),
83 'http://www.w3.org/1999/02/22-rdf-syntax-ns#')
85 self.assertEqual(RDFXMLReader.get_cim_ns(ns),
86 (nsURICIM15, packageMapCIM15))
89 if __name__ == "__main__":
90 import logging
91 logging.basicConfig(level=logging.INFO)
92 unittest.main()