Skip to content

Commit

Permalink
Bugfixes for 1.0.1 (#169)
Browse files Browse the repository at this point in the history
* Fixed issues with namespaces (#166, #167 and #168)
  • Loading branch information
joelebwf authored May 24, 2019
1 parent 67d905a commit 676e877
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 16 deletions.
15 changes: 11 additions & 4 deletions oblib/data_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,8 @@ def __init__(self, **kwargs):
if not keyword.endswith("Axis"):
raise OBContextError("Context given invalid keyword {}".format(keyword))
qualified_name = keyword
if not qualified_name.startswith("solar:"):
# Add solar: namespace iff no namespace is present.
if ":" not in qualified_name:
qualified_name = "solar:" + keyword
self.axes[qualified_name] = kwargs[keyword]

Expand Down Expand Up @@ -823,7 +824,13 @@ def get_domain(self):
# that it can be easily translated to an actual domain name by just replacing
# "#solar_" with "solar": but a better approach would be to look up the element
# matching the ID and read the name from that element.
return domain_ref.replace("#solar_", "solar:")
# Also dei and us-gaap namespaces follow same patter.
if "#solar_" in domain_ref:
return domain_ref.replace("#solar_", "solar:")
elif "#dei_" in domain_ref:
return domain_ref.replace("#dei_", "dei:")
elif "#dei_" in domain_ref:
return domain_ref.replace("#us-gaap_", "us-gaap:")
return None


Expand Down Expand Up @@ -900,7 +907,7 @@ def __init__(self, entrypoint_name, taxonomy, dev_validation_off=False):
self._initialize_tables()

self.facts = {}
self.taxonomy_name = "https://raw.githubusercontent.com/xbrlus/solar/v1.2/core/solar_2018-03-31_r01.xsd"
self.taxonomy_name = "https://raw.githubusercontent.com/SunSpecOrangeButton/solar-taxonomy/master/core/solar_all_2019-02-27_r01.xsd"
self._default_context = {}

def _initialize_concepts(self, concept_name_list):
Expand Down Expand Up @@ -981,7 +988,7 @@ def _get_namespaces(self):
"xmlns:xsi": "http://www.w3.org/2001/XMRLSchema-instance",
"xmlns:units": "http://www.xbrl.org/2009/utr",
"xmlns:xbrldi": "http://xbrl.org/2006/xbrldi",
"xmlns:solar": "http://xbrl.us/Solar/v1.2/2018-03-31/solar"
"xmlns:solar": "http://xbrl.us/Solar/v1.3/2019-02-27/solar"
}

# The following namespaces are optional and are included in the header
Expand Down
6 changes: 3 additions & 3 deletions oblib/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

_xml_ns = {"xbrldi:": "{http://xbrl.org/2006/xbrldi}",
"link:": "{http://www.xbrl.org/2003/linkbase}",
"solar:": "{http://xbrl.us/Solar/v1.2/2018-03-31/solar}",
"solar:": "{http://xbrl.us/Solar/v1.3/2019-02-27/solar}",
"dei:": "{http://xbrl.sec.gov/dei/2014-01-31}",
"us-gaap:": "{http://fasb.org/us-gaap/2017-01-31}"}

Expand Down Expand Up @@ -335,7 +335,7 @@ def from_XML_string(self, xml_string, entrypoint_name=None):
if child.tag != _xn("link:schemaRef") and child.tag != _xn("unit") and child.tag != _xn("context"):

tag = child.tag
tag = tag.replace("{http://xbrl.us/Solar/v1.2/2018-03-31/solar}", "solar:")
tag = tag.replace("{http://xbrl.us/Solar/v1.3/2019-02-27/solar}", "solar:")
tag = tag.replace("{http://fasb.org/us-gaap/2017-01-31}", "us-gaap:")
tag = tag.replace("{http://xbrl.sec.gov/dei/2014-01-31}", "dei:")
fact_names.append(tag)
Expand Down Expand Up @@ -422,7 +422,7 @@ def from_XML_string(self, xml_string, entrypoint_name=None):
kwargs["context"] = contexts[child.attrib["contextRef"]]
kwargs["fact_id"] = fact_id
tag = child.tag
tag = tag.replace("{http://xbrl.us/Solar/v1.2/2018-03-31/solar}", "solar:")
tag = tag.replace("{http://xbrl.us/Solar/v1.3/2019-02-27/solar}", "solar:")
tag = tag.replace("{http://fasb.org/us-gaap/2017-01-31}", "us-gaap:")
tag = tag.replace("{http://xbrl.sec.gov/dei/2014-01-31}", "dei:")
try:
Expand Down
18 changes: 13 additions & 5 deletions oblib/tests/test_data_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -363,10 +363,10 @@ def test_conversion_to_xml(self):
'solar:TestConditionAxis'])
for axis in axes:
if axis.attrib["dimension"] == 'solar:ProductIdentifierAxis':
self.assertEqual(axis.getchildren()[0].tag, "{http://xbrl.us/Solar/v1.2/2018-03-31/solar}ProductIdentifierDomain")
self.assertEqual(axis.getchildren()[0].tag, "{http://xbrl.us/Solar/v1.3/2019-02-27/solar}ProductIdentifierDomain")
self.assertEqual(axis.getchildren()[0].text, "placeholder")
elif axis.attrib["dimension"] == 'solar:TestConditionsAxis':
self.assertEqual(axis.getchildren()[0].tag, "{http://xbrl.us/Solar/v1.2/2018-03-31/solar}TestConditionDomain")
self.assertEqual(axis.getchildren()[0].tag, "{http://xbrl.us/Solar/v1.3/2019-02-27/solar}TestConditionDomain")
self.assertEqual(axis.getchildren()[0].text, "solar:StandardTestConditionMember")

# one should have period containing <forever/> other should have period containing <instant> containing today's date.
Expand All @@ -383,8 +383,8 @@ def test_conversion_to_xml(self):

# Expect to see two facts solar:DeviceCost and solar:TypeOfDevice,
# each containing text of the fact value
costFact = root.find('{http://xbrl.us/Solar/v1.2/2018-03-31/solar}DeviceCost')
typeFact = root.find('{http://xbrl.us/Solar/v1.2/2018-03-31/solar}TypeOfDevice')
costFact = root.find('{http://xbrl.us/Solar/v1.3/2019-02-27/solar}DeviceCost')
typeFact = root.find('{http://xbrl.us/Solar/v1.3/2019-02-27/solar}TypeOfDevice')
self.assertEqual(costFact.text, "100")
self.assertEqual(typeFact.text, "ModuleMember")
# They should have contextRef and (in the case of cost) unitRef attributes:
Expand Down Expand Up @@ -842,7 +842,7 @@ def test_ids_in_xml_and_json(self):
# Look for fact ID in XML:
xml = doc.to_XML_string()
root = etree.fromstring(xml)
fact = root.find("{http://xbrl.us/Solar/v1.2/2018-03-31/solar}ModuleNameplateCapacity")
fact = root.find("{http://xbrl.us/Solar/v1.3/2019-02-27/solar}ModuleNameplateCapacity")
self.assertEqual(fact.attrib["id"], fact_id)

def test_input_ids(self):
Expand Down Expand Up @@ -983,3 +983,11 @@ def test_all_entrypoint(self):

# TODO test that concepts with Axis in the name get instantiated as Axis subclass of
# Concept.

def test_ct_issue(self):
# Test for issue found in create_templates program
doc = data_model.OBInstance("Project", self.taxonomy)
kwargs = {'duration': 'forever', 'entity': 'PLUTO',
'us-gaap:SaleLeasebackTransactionDescriptionAxis': 'us-gaap:SaleLeasebackTransactionNameDomain',
'solar:ProjectIdentifierAxis': '1'}
doc.set('us-gaap:SaleLeasebackTransactionDescription', 'Sample String', **kwargs)
8 changes: 4 additions & 4 deletions oblib/tests/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,15 @@ def test_files(self):
"documentType": "http://www.xbrl.org/WGWD/YYYY-MM-DD/xbrl-json",
"prefixes": {
"xbrl": "http://www.xbrl.org/WGWD/YYYY-MM-DD/oim",
"solar": "http://xbrl.us/Solar/v1.1/2018-02-09/solar",
"solar": "http://xbrl.us/Solar/v1.3/2019-02-27/solar",
"us-gaap": "http://fasb.org/us-gaap/2017-01-31",
"iso4217": "http://www.xbrl.org/2003/iso4217",
"SI": "http://www.xbrl.org/2009/utr"
},
"dtsReferences": [
{
"type": "schema",
"href": "https://raw.githubusercontent.com/xbrlus/solar/v1.2/core/solar_all_2018-03-31_r01.xsd"
"href": "https://raw.githubusercontent.com/SunSpecOrangeButton/solar-taxonomy/master/core/solar_all_2019-02-27_r01.xsd"
}
],
"facts": {
Expand Down Expand Up @@ -111,7 +111,7 @@ def test_files(self):
<xbrl
xmlns="http://www.xbrl.org/2003/instance"
xmlns:link="http://www.xbrl.org/2003/linkbase"
xmlns:solar="http://xbrl.us/Solar/v1.2/2018-03-31/solar"
xmlns:solar="http://xbrl.us/Solar/v1.3/2019-02-27/solar"
xmlns:units="http://www.xbrl.org/2009/utr"
xmlns:xbrldi="http://xbrl.org/2006/xbrldi"
xmlns:xlink="http://www.w3.org/1999/xlink"
Expand Down Expand Up @@ -146,7 +146,7 @@ def test_files(self):
<xbrl
xmlns="http://www.xbrl.org/2003/instance"
xmlns:link="http://www.xbrl.org/2003/linkbase"
xmlns:solar="http://xbrl.us/Solar/v1.2/2018-03-31/solar"
xmlns:solar="http://xbrl.us/Solar/v1.3/2019-02-27/solar"
xmlns:units="http://www.xbrl.org/2009/utr"
xmlns:xbrldi="http://xbrl.org/2006/xbrldi"
xmlns:xlink="http://www.w3.org/1999/xlink"
Expand Down

0 comments on commit 676e877

Please sign in to comment.