Exemplo n.º 1
0
    def test_graph(self):
        ureg = UnitRegistry()
        add_ctxs(ureg)
        l = _freeze({'[length]': 1.})
        t = _freeze({'[time]': -1.})
        c = _freeze({'[current]': -1.})

        g_sp = defaultdict(set)
        g_sp.update({
            l: {
                t,
            },
            t: {
                l,
            }
        })

        g_ab = defaultdict(set)
        g_ab.update({
            l: {
                c,
            },
            c: {
                l,
            }
        })

        g = defaultdict(set)
        g.update({
            l: {t, c},
            t: {
                l,
            },
            c: {
                l,
            }
        })

        with ureg.context('lc'):
            self.assertEqual(ureg._active_ctx.graph, g_sp)

        with ureg.context('lc', n=1):
            self.assertEqual(ureg._active_ctx.graph, g_sp)

        with ureg.context('ab'):
            self.assertEqual(ureg._active_ctx.graph, g_ab)

        with ureg.context('lc'):
            with ureg.context('ab'):
                self.assertEqual(ureg._active_ctx.graph, g)

        with ureg.context('ab'):
            with ureg.context('lc'):
                self.assertEqual(ureg._active_ctx.graph, g)

        with ureg.context('lc', 'ab'):
            self.assertEqual(ureg._active_ctx.graph, g)

        with ureg.context('ab', 'lc'):
            self.assertEqual(ureg._active_ctx.graph, g)
Exemplo n.º 2
0
 def test_freeze(self):
     self.assertEqual(_freeze("meter"), frozenset([("meter", 1)]))
     self.assertEqual(_freeze("meter/second"), frozenset((("meter", 1), ("second", -1))))
     x = frozenset((("meter", 1)))
     self.assertIs(_freeze(x), x)
     self.assertEqual(_freeze({"meter": 1}), frozenset([("meter", 1)]))
     self.assertEqual(_freeze({"meter": -1, "second": -1}), frozenset((("meter", -1), ("second", -1))))
Exemplo n.º 3
0
 def test_freeze(self):
     self.assertEqual(_freeze('meter'), frozenset([('meter', 1)]))
     self.assertEqual(_freeze('meter/second'), frozenset((('meter', 1), ('second', -1))))
     x = frozenset((('meter', 1)))
     self.assertIs(_freeze(x), x)
     self.assertEqual(_freeze({'meter': 1}),
                      frozenset([('meter', 1)]))
     self.assertEqual(_freeze({'meter': -1, 'second': -1}),
                      frozenset((('meter', -1), ('second', -1))))
Exemplo n.º 4
0
 def test_freeze(self):
     self.assertEqual(_freeze('meter'), frozenset([('meter', 1)]))
     self.assertEqual(_freeze('meter/second'), frozenset((('meter', 1), ('second', -1))))
     x = frozenset((('meter', 1)))
     self.assertIs(_freeze(x), x)
     self.assertEqual(_freeze({'meter': 1}),
                      frozenset([('meter', 1)]))
     self.assertEqual(_freeze({'meter': -1, 'second': -1}),
                      frozenset((('meter', -1), ('second', -1))))
Exemplo n.º 5
0
    def test_graph_enable(self):
        ureg = UnitRegistry()
        add_ctxs(ureg)
        l = _freeze({'[length]': 1.})
        t = _freeze({'[time]': -1.})
        c = _freeze({'[current]': -1.})

        g_sp = defaultdict(set)
        g_sp.update({l: {t, },
                     t: {l, }})

        g_ab = defaultdict(set)
        g_ab.update({l: {c, },
                     c: {l, }})

        g = defaultdict(set)
        g.update({l: {t, c},
                  t: {l, },
                  c: {l, }})

        ureg.enable_contexts('lc')
        self.assertEqual(ureg._active_ctx.graph, g_sp)
        ureg.disable_contexts(1)

        ureg.enable_contexts('lc', n=1)
        self.assertEqual(ureg._active_ctx.graph, g_sp)
        ureg.disable_contexts(1)

        ureg.enable_contexts('ab')
        self.assertEqual(ureg._active_ctx.graph, g_ab)
        ureg.disable_contexts(1)

        ureg.enable_contexts('lc')
        ureg.enable_contexts('ab')
        self.assertEqual(ureg._active_ctx.graph, g)
        ureg.disable_contexts(2)

        ureg.enable_contexts('ab')
        ureg.enable_contexts('lc')
        self.assertEqual(ureg._active_ctx.graph, g)
        ureg.disable_contexts(2)

        ureg.enable_contexts('lc', 'ab')
        self.assertEqual(ureg._active_ctx.graph, g)
        ureg.disable_contexts(2)

        ureg.enable_contexts('ab', 'lc')
        self.assertEqual(ureg._active_ctx.graph, g)
        ureg.disable_contexts(2)
Exemplo n.º 6
0
    def test_graph_enable(self):
        ureg = UnitRegistry()
        add_ctxs(ureg)
        l = _freeze({'[length]': 1.})
        t = _freeze({'[time]': -1.})
        c = _freeze({'[current]': -1.})

        g_sp = defaultdict(set)
        g_sp.update({l: set((t,)),
                     t: set((l,))})

        g_ab = defaultdict(set)
        g_ab.update({l: set((c,)),
                     c: set((l,))})

        g = defaultdict(set)
        g.update({l: set((t, c)),
                  t: set((l,)),
                  c: set((l,))})

        ureg.enable_contexts('lc')
        self.assertEqual(ureg._active_ctx.graph, g_sp)
        ureg.disable_contexts(1)

        ureg.enable_contexts('lc', n=1)
        self.assertEqual(ureg._active_ctx.graph, g_sp)
        ureg.disable_contexts(1)

        ureg.enable_contexts('ab')
        self.assertEqual(ureg._active_ctx.graph, g_ab)
        ureg.disable_contexts(1)

        ureg.enable_contexts('lc')
        ureg.enable_contexts('ab')
        self.assertEqual(ureg._active_ctx.graph, g)
        ureg.disable_contexts(2)

        ureg.enable_contexts('ab')
        ureg.enable_contexts('lc')
        self.assertEqual(ureg._active_ctx.graph, g)
        ureg.disable_contexts(2)

        ureg.enable_contexts('lc', 'ab')
        self.assertEqual(ureg._active_ctx.graph, g)
        ureg.disable_contexts(2)

        ureg.enable_contexts('ab', 'lc')
        self.assertEqual(ureg._active_ctx.graph, g)
        ureg.disable_contexts(2)
Exemplo n.º 7
0
    def test_graph_enable(self):
        ureg = UnitRegistry()
        add_ctxs(ureg)
        l = _freeze({"[length]": 1.0})
        t = _freeze({"[time]": -1.0})
        c = _freeze({"[current]": -1.0})

        g_sp = defaultdict(set)
        g_sp.update({l: set((t,)), t: set((l,))})

        g_ab = defaultdict(set)
        g_ab.update({l: set((c,)), c: set((l,))})

        g = defaultdict(set)
        g.update({l: set((t, c)), t: set((l,)), c: set((l,))})

        ureg.enable_contexts("lc")
        self.assertEqual(ureg._active_ctx.graph, g_sp)
        ureg.disable_contexts(1)

        ureg.enable_contexts("lc", n=1)
        self.assertEqual(ureg._active_ctx.graph, g_sp)
        ureg.disable_contexts(1)

        ureg.enable_contexts("ab")
        self.assertEqual(ureg._active_ctx.graph, g_ab)
        ureg.disable_contexts(1)

        ureg.enable_contexts("lc")
        ureg.enable_contexts("ab")
        self.assertEqual(ureg._active_ctx.graph, g)
        ureg.disable_contexts(2)

        ureg.enable_contexts("ab")
        ureg.enable_contexts("lc")
        self.assertEqual(ureg._active_ctx.graph, g)
        ureg.disable_contexts(2)

        ureg.enable_contexts("lc", "ab")
        self.assertEqual(ureg._active_ctx.graph, g)
        ureg.disable_contexts(2)

        ureg.enable_contexts("ab", "lc")
        self.assertEqual(ureg._active_ctx.graph, g)
        ureg.disable_contexts(2)
Exemplo n.º 8
0
    def test_graph(self):
        ureg = UnitRegistry()
        add_ctxs(ureg)
        l = _freeze({'[length]': 1.})
        t = _freeze({'[time]': -1.})
        c = _freeze({'[current]': -1.})

        g_sp = defaultdict(set)
        g_sp.update({l: {t, },
                     t: {l, }})

        g_ab = defaultdict(set)
        g_ab.update({l: {c, },
                     c: {l, }})

        g = defaultdict(set)
        g.update({l: {t, c},
                  t: {l, },
                  c: {l, }})

        with ureg.context('lc'):
            self.assertEqual(ureg._active_ctx.graph, g_sp)

        with ureg.context('lc', n=1):
            self.assertEqual(ureg._active_ctx.graph, g_sp)

        with ureg.context('ab'):
            self.assertEqual(ureg._active_ctx.graph, g_ab)

        with ureg.context('lc'):
            with ureg.context('ab'):
                self.assertEqual(ureg._active_ctx.graph, g)

        with ureg.context('ab'):
            with ureg.context('lc'):
                self.assertEqual(ureg._active_ctx.graph, g)

        with ureg.context('lc', 'ab'):
            self.assertEqual(ureg._active_ctx.graph, g)

        with ureg.context('ab', 'lc'):
            self.assertEqual(ureg._active_ctx.graph, g)
Exemplo n.º 9
0
    def test_graph(self):
        ureg = UnitRegistry()
        add_ctxs(ureg)
        l = _freeze({"[length]": 1.0})
        t = _freeze({"[time]": -1.0})
        c = _freeze({"[current]": -1.0})

        g_sp = defaultdict(set)
        g_sp.update({l: set((t,)), t: set((l,))})

        g_ab = defaultdict(set)
        g_ab.update({l: set((c,)), c: set((l,))})

        g = defaultdict(set)
        g.update({l: set((t, c)), t: set((l,)), c: set((l,))})

        with ureg.context("lc"):
            self.assertEqual(ureg._active_ctx.graph, g_sp)

        with ureg.context("lc", n=1):
            self.assertEqual(ureg._active_ctx.graph, g_sp)

        with ureg.context("ab"):
            self.assertEqual(ureg._active_ctx.graph, g_ab)

        with ureg.context("lc"):
            with ureg.context("ab"):
                self.assertEqual(ureg._active_ctx.graph, g)

        with ureg.context("ab"):
            with ureg.context("lc"):
                self.assertEqual(ureg._active_ctx.graph, g)

        with ureg.context("lc", "ab"):
            self.assertEqual(ureg._active_ctx.graph, g)

        with ureg.context("ab", "lc"):
            self.assertEqual(ureg._active_ctx.graph, g)