示例#1
0
    def test_set_context_arg(self):
        # Tests the case where .set() is called correctly, using
        # the way of calling .set() where we pass in a Context
        # object. Verify the data is stored and can be retrieved
        # using .get().
        doc = Entrypoint("CutSheet", self.taxonomy)
        ctx = Context(duration="forever",
                      entity="JUPITER",
                      ProductIdentifierAxis="placeholder",
                      TestConditionAxis="solar:StandardTestConditionMember")
        doc.set("solar:TypeOfDevice", "ModuleMember", context=ctx)

        now = datetime.now(),
        ctx = Context(instant=now,
                      entity="JUPITER",
                      ProductIdentifierAxis="placeholder",
                      TestConditionAxis="solar:StandardTestConditionMember")
        doc.set("solar:DeviceCost", 100, context=ctx, unit_name="USD")

        # Get the data bacK:
        typeFact = doc.get(
            "solar:TypeOfDevice",
            Context(duration="forever",
                    entity="JUPITER",
                    ProductIdentifierAxis="placeholder",
                    TestConditionAxis="solar:StandardTestConditionMember"))
        self.assertEqual(typeFact.value, "ModuleMember")
        costFact = doc.get(
            "solar:DeviceCost",
            Context(instant=now,
                    entity="JUPITER",
                    ProductIdentifierAxis="placeholder",
                    TestConditionAxis="solar:StandardTestConditionMember"))
        self.assertEqual(costFact.value, 100)
示例#2
0
    def test_set_separate_dimension_args(self):
        # Tests the case where .set() is called correctly.  Use the
        # way of calling .set() where we pass in every dimension
        # separately. Verify the data is stored and can be retrieved
        # using .get().
        doc = Entrypoint("CutSheet", self.taxonomy)

        # Write a TypeOfDevice and a DeviceCost:

        doc.set(
            "solar:TypeOfDevice",
            "Module",
            duration="forever",
            ProductIdentifierAxis="placeholder",
            TestConditionAxis="placeholder",
        )
        doc.set("solar:DeviceCost",
                100,
                instant=datetime.now(),
                ProductIdentifierAxis="placeholder",
                TestConditionAxis="placeholder",
                unit="dollars")

        self.assertEqual(doc.get("solar:TypeOfDevice", {}), "Module")
        self.assertEqual(doc.get("solar:DeviceCost", {}), 100)
示例#3
0
    def test_set_separate_dimension_args(self):
        # Tests the case where .set() is called correctly.  Use the
        # way of calling .set() where we pass in every dimension
        # separately. Verify the data is stored and can be retrieved
        # using .get().
        doc = Entrypoint("CutSheet", self.taxonomy)

        # Write a TypeOfDevice and a DeviceCost:

        doc.set("solar:TypeOfDevice",
                "ModuleMember",
                duration="forever",
                ProductIdentifierAxis="placeholder",
                TestConditionAxis="solar:StandardTestConditionMember")
        now = datetime.now()
        doc.set("solar:DeviceCost",
                100,
                instant=now,
                ProductIdentifierAxis="placeholder",
                TestConditionAxis="solar:StandardTestConditionMember",
                unit_name="USD")

        typeFact = doc.get(
            "solar:TypeOfDevice",
            Context(duration="forever",
                    ProductIdentifierAxis="placeholder",
                    TestConditionAxis="solar:StandardTestConditionMember"))
        self.assertEqual(typeFact.value, "ModuleMember")
        costFact = doc.get(
            "solar:DeviceCost",
            Context(instant=now,
                    ProductIdentifierAxis="placeholder",
                    TestConditionAxis="solar:StandardTestConditionMember"))
        self.assertEqual(costFact.value, 100)
        self.assertEqual(costFact.unit, "USD")
示例#4
0
    def test_facts_stored_with_context(self):
        # Test we can store 2 facts of the same concept but with different
        # contexts, and pull them both back out.
        doc = Entrypoint("CutSheet", self.taxonomy)
        concept = "solar:InverterCutSheetNotes"

        ctx_jan = Context(
            duration={
                "start": datetime(year=2018, month=1, day=1),
                "end": datetime(year=2018, month=2, day=1)
            },
            entity="JUPITER",
            ProductIdentifierAxis="placeholder",
            TestConditionAxis="solar:StandardTestConditionMember")
        ctx_feb = Context(
            duration={
                "start": datetime(year=2018, month=2, day=1),
                "end": datetime(year=2018, month=3, day=1)
            },
            entity="JUPITER",
            ProductIdentifierAxis="placeholder",
            TestConditionAxis="solar:StandardTestConditionMember")

        doc.set(concept, "Jan Value", context=ctx_jan)
        doc.set(concept, "Feb Value", context=ctx_feb)

        jan_fact = doc.get(concept, context=ctx_jan)
        feb_fact = doc.get(concept, context=ctx_feb)

        self.assertEqual(jan_fact.value, "Jan Value")
        self.assertEqual(feb_fact.value, "Feb Value")
示例#5
0
    def test_set_and_get(self):
        # Tests the case where .set() is called correctly. Verify the
        # data is stored and can be retrieved using .get().
        doc = Entrypoint("CutSheet")

        # Write a TypeOfDevice and a DeviceCost:

        doc.set(
            "solar:TypeOfDevice", "Module", {
                "duration": "forever",
                "solar:ProductIdentifierAxis": "placeholder",
                "solar:TestConditionAxis": "placeholder"
            })
        doc.set(
            "solar:DeviceCost", 100, {
                "instant": datetime.now(),
                "solar:ProductIdentifierAxis": "placeholder",
                "solar:TestConditionAxis": "placeholder"
            })

        self.assertEqual(doc.get("solar:TypeOfDevice", {}), "Module")
        self.assertEqual(doc.get("solar:DeviceCost", {}), 100)
示例#6
0
    def test_tableless_facts(self):
        # Some entry points, like MonthlyOperatingReport, seem to have concepts
        # in them that are not part of any table:
        doc = Entrypoint("MonthlyOperatingReport", self.taxonomy)

        doc.set("solar:MonthlyOperatingReportEffectiveDate",
                date(year=2018, month=6, day=1),
                entity="JUPITER",
                duration="forever")

        fact = doc.get("solar:MonthlyOperatingReportEffectiveDate",
                       Context(entity="JUPITER", duration="forever"))

        self.assertEqual(fact.value, date(year=2018, month=6, day=1))
示例#7
0
    def test_set_default_context_values(self):
        # Test setting default values, for example something like:
        doc = Entrypoint("CutSheet", self.taxonomy)
        now = datetime.now()
        doc.set_default_context({
            "entity": "JUPITER",
            "solar:TestConditionAxis": "solar:StandardTestConditionMember",
            PeriodType.instant: now,
            PeriodType.duration: "forever"
        })
        # Could also support setting default unit, even though that's not part of context:

        # If we set a fact that wants an instant context, it should use 'now':
        doc.set("solar:DeviceCost",
                "100",
                unit_name="USD",
                ProductIdentifierAxis="placeholder")
        # This would normally raise an exception because it's missing instant, entity, and
        # TestConditionAxis. But we set defaults for those, so they should be filled in:
        fact = doc.get(
            "solar:DeviceCost",
            Context(ProductIdentifierAxis="placeholder",
                    TestConditionAxis="solar:StandardTestConditionMember",
                    entity="JUPITER",
                    instant=now))
        self.assertEqual(fact.value, "100")
        self.assertEqual(fact.unit, "USD")
        self.assertEqual(fact.context.entity, "JUPITER")
        self.assertEqual(fact.context.instant, now)

        # TODO test method of calling set() where we pass in Context object.

        # If we set a fact that wants a duration context, it should use jan 1 - jan 31:
        doc.set("solar:ModuleNameplateCapacity",
                "0.3",
                unit_name="W",
                ProductIdentifierAxis="placeholder")
        # Would normally raise an exception because missing duration, entity, and
        # TestConditionAxis. But we set defaults for those, so they should be filled in:
        fact = doc.get(
            "solar:ModuleNameplateCapacity",
            Context(ProductIdentifierAxis="placeholder",
                    TestConditionAxis="solar:StandardTestConditionMember",
                    entity="JUPITER",
                    duration="forever"))
        self.assertEqual(fact.value, "0.3")
        self.assertEqual(fact.unit, "W")
        self.assertEqual(fact.context.entity, "JUPITER")
        self.assertEqual(fact.context.duration, "forever")

        # Try setting ALL the fields in set_default_context and then pass in NO context fields,
        # that should work too:
        doc.set_default_context({
            "entity": "JUPITER",
            "solar:TestConditionAxis": "solar:StandardTestConditionMember",
            PeriodType.instant: now,
            "solar:ProductIdentifierAxis": "placeholder"
        })
        doc.set("solar:DeviceCost", "99", unit_name="USD")
        fact = doc.get(
            "solar:DeviceCost",
            Context(ProductIdentifierAxis="placeholder",
                    TestConditionAxis="solar:StandardTestConditionMember",
                    entity="JUPITER",
                    instant=now))
        self.assertEqual(fact.value, "99")