Esempio n. 1
0
    def test_sufficient_context(self):
        doc = Entrypoint("CutSheet")

        # in order to set a concept value, sufficient context must be
        # provided. what is sufficient context varies by concept.
        # in general the context must provide the correct time information
        # (either duration or instant)

        # solar:DeviceCost has period_type instant
        # so it requires a context with an instant. A context without an instant
        # should be insufficient:
        noTimeContext = {
            "solar:ProductIdentifierAxis": "placeholder",
            "solar:TestConditionAxis": "placeholder"
        }
        instantContext = {
            "solar:ProductIdentifierAxis": "placeholder",
            "solar:TestConditionAxis": "placeholder",
            "instant": datetime.now()
        }
        durationContext = {
            "solar:ProductIdentifierAxis": "placeholder",
            "solar:TestConditionAxis": "placeholder",
            "duration": "forever"
        }

        with self.assertRaises(Exception):
            doc.sufficientContext("solar:DeviceCost", noTimeContext)
        self.assertTrue(
            doc.sufficientContext("solar:DeviceCost", instantContext))
        # A context with a duration instead of an instant should also be
        # rejected:
        with self.assertRaises(Exception):
            doc.sufficientContext("solar:DeviceCost", durationContext)

        # solar:ModuleNameplateCapacity has period_type duration. A context
        # without a duration should be insufficient:
        with self.assertRaises(Exception):
            doc.sufficientContext("solar:ModuleNameplateCapacity",
                                  noTimeContext)
        # A context with an instant instead of a duration should also be
        # rejected:
        with self.assertRaises(Exception):
            doc.sufficientContext("solar:ModuleNameplateCapacity",
                                  instantContext)
        self.assertTrue(
            doc.sufficientContext("solar:ModuleNameplateCapacity",
                                  durationContext))
Esempio n. 2
0
    def test_sufficient_context_instant_vs_duration(self):
        doc = Entrypoint("CutSheet", self.taxonomy)

        # in order to set a concept value, sufficient context must be
        # provided. what is sufficient context varies by concept.
        # in general the context must provide the correct time information
        # (either duration or instant)

        # We shouldn't even be able to instantiate a context with no time info:
        with self.assertRaises(Exception):
            noTimeContext = Context(ProductIdentifierAxis="placeholder",
                                    TestConditionAxis="placeholder")

        # solar:DeviceCost has period_type instant
        # so it requires a context with an instant. A context without an instant
        # should be insufficient:
        instantContext = Context(ProductIdentifierAxis="placeholder",
                                 TestConditionAxis="placeholder",
                                 instant=datetime.now())
        durationContext = Context(ProductIdentifierAxis="placeholder",
                                  TestConditionAxis="placeholder",
                                  duration="forever")

        self.assertTrue(
            doc.sufficientContext("solar:DeviceCost", instantContext))
        # A context with a duration instead of an instant should also be
        # rejected:
        with self.assertRaises(Exception):
            doc.sufficientContext("solar:DeviceCost", durationContext)

        # solar:ModuleNameplateCapacity has period_type duration.
        # A context with an instant instead of a duration should also be
        # rejected:
        with self.assertRaises(Exception):
            doc.sufficientContext("solar:ModuleNameplateCapacity",
                                  instantContext)
        self.assertTrue(
            doc.sufficientContext("solar:ModuleNameplateCapacity",
                                  durationContext))
Esempio n. 3
0
    def test_sufficient_context_axes(self):
        doc = Entrypoint("CutSheet", self.taxonomy)

        # The context must also provide all of the axes needed to place the
        # fact within the right table.

        # DeviceCost is on the CutSheetDetailsTable so it needs a value
        # for ProductIdentifierAxis and TestConditionAxis.
        with self.assertRaises(Exception):
            doc.sufficientContext("solar:DeviceCost", {})

        context = Context(instant=datetime.now(),
                          ProductIdentifierAxis="placeholder",
                          TestConditionAxis="placeholder")
        self.assertTrue(doc.sufficientContext("solar:DeviceCost", context))

        badContext = Context(instant=datetime.now(),
                             TestConditionAxis="placeholder")
        with self.assertRaises(Exception):
            doc.sufficientContext("solar:DeviceCost", badContext)

        badContext = Context(instant=datetime.now(),
                             ProductIdentifierAxis="placeholder")
        with self.assertRaises(Exception):
            doc.sufficientContext("solar:DeviceCost", badContext)

        # How do we know what are valid values for ProductIdentifierAxis and
        # TestConditionAxis?  (I think they are meant to be UUIDs.)

        # Note: TestConditionAxis is part of the following relationships:
        # solar:TestConditionAxis -> dimension-domain -> solar:TestConditionDomain
        # solar:TestConditionAxis -> dimension-default -> solar:TestConditionDomain
        # i wonder what that "dimension-default" means

        #'solar:InverterOutputRatedPowerAC' is on the 'solar:InverterPowerLevelTable' which requires axes: [u'solar:ProductIdentifierAxis', u'solar:InverterPowerLevelPercentAxis']. it's a duration.
        concept = 'solar:InverterOutputRatedPowerAC'
        context = Context(duration="forever",
                          ProductIdentifierAxis="placeholder",
                          InverterPowerLevelPercentAxis="placeholder")
        self.assertTrue(doc.sufficientContext(concept, context))

        badContext = Context(instant=datetime.now(),
                             InverterPowerLevelPercentAxis="placeholder")
        with self.assertRaises(Exception):
            doc.sufficientContext(concept, badContext)

        badContext = Context(instant=datetime.now(),
                             ProductIdentifierAxis="placeholder")
        with self.assertRaises(Exception):
            doc.sufficientContext(concept, badContext)