当前位置: 首页>>代码示例>>Python>>正文


Python Context.__keytransform__方法代码示例

本文整理汇总了Python中pint.context.Context.__keytransform__方法的典型用法代码示例。如果您正苦于以下问题:Python Context.__keytransform__方法的具体用法?Python Context.__keytransform__怎么用?Python Context.__keytransform__使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pint.context.Context的用法示例。


在下文中一共展示了Context.__keytransform__方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_parse_simple

# 需要导入模块: from pint.context import Context [as 别名]
# 或者: from pint.context.Context import __keytransform__ [as 别名]
    def test_parse_simple(self):

        a = Context.__keytransform__(UnitsContainer({"[time]": -1}), UnitsContainer({"[length]": 1}))
        b = Context.__keytransform__(UnitsContainer({"[length]": 1}), UnitsContainer({"[time]": -1}))

        s = ["@context longcontextname", "[length] -> 1 / [time]: c / value", "1 / [time] -> [length]: c / value"]

        c = Context.from_lines(s)
        self.assertEqual(c.name, "longcontextname")
        self.assertEqual(c.aliases, ())
        self.assertEqual(c.defaults, {})
        self.assertEqual(set(c.funcs.keys()), set((a, b)))
        self._test_ctx(c)

        s = ["@context longcontextname = lc", "[length] <-> 1 / [time]: c / value"]

        c = Context.from_lines(s)
        self.assertEqual(c.name, "longcontextname")
        self.assertEqual(c.aliases, ("lc",))
        self.assertEqual(c.defaults, {})
        self.assertEqual(set(c.funcs.keys()), set((a, b)))
        self._test_ctx(c)

        s = ["@context longcontextname = lc = lcn", "[length] <-> 1 / [time]: c / value"]

        c = Context.from_lines(s)
        self.assertEqual(c.name, "longcontextname")
        self.assertEqual(c.aliases, ("lc", "lcn"))
        self.assertEqual(c.defaults, {})
        self.assertEqual(set(c.funcs.keys()), set((a, b)))
        self._test_ctx(c)
开发者ID:JonasOlson,项目名称:pint,代码行数:33,代码来源:test_contexts.py

示例2: test_parse_simple

# 需要导入模块: from pint.context import Context [as 别名]
# 或者: from pint.context.Context import __keytransform__ [as 别名]
    def test_parse_simple(self):

        a = Context.__keytransform__(UnitsContainer({'[time]': -1}), UnitsContainer({'[length]': 1}))
        b = Context.__keytransform__(UnitsContainer({'[length]': 1}), UnitsContainer({'[time]': -1}))

        s = ['@context longcontextname',
             '[length] -> 1 / [time]: c / value',
             '1 / [time] -> [length]: c / value']

        c = Context.from_lines(s)
        self.assertEqual(c.name, 'longcontextname')
        self.assertEqual(c.aliases, ())
        self.assertEqual(c.defaults, {})
        self.assertEqual(set(c.funcs.keys()), set((a, b)))
        self._test_ctx(c)

        s = ['@context longcontextname = lc',
             '[length] <-> 1 / [time]: c / value']

        c = Context.from_lines(s)
        self.assertEqual(c.name, 'longcontextname')
        self.assertEqual(c.aliases, ('lc', ))
        self.assertEqual(c.defaults, {})
        self.assertEqual(set(c.funcs.keys()), set((a, b)))
        self._test_ctx(c)

        s = ['@context longcontextname = lc = lcn',
             '[length] <-> 1 / [time]: c / value']

        c = Context.from_lines(s)
        self.assertEqual(c.name, 'longcontextname')
        self.assertEqual(c.aliases, ('lc', 'lcn', ))
        self.assertEqual(c.defaults, {})
        self.assertEqual(set(c.funcs.keys()), set((a, b)))
        self._test_ctx(c)
开发者ID:Aircraft-Design-UniNa,项目名称:SUAVE,代码行数:37,代码来源:test_contexts.py

示例3: test_parse_define

# 需要导入模块: from pint.context import Context [as 别名]
# 或者: from pint.context.Context import __keytransform__ [as 别名]
    def test_parse_define(self):
        a = Context.__keytransform__(UnitsContainer({"[time]": -1}), UnitsContainer({"[length]": 1.0}))
        b = Context.__keytransform__(UnitsContainer({"[length]": 1}), UnitsContainer({"[time]": -1.0}))

        s = ["@context longcontextname", "[length] <-> 1 / [time]: c / value"]
        c = Context.from_lines(s)
        self.assertEqual(c.defaults, {})
        self.assertEqual(set(c.funcs.keys()), set((a, b)))
        self._test_ctx(c)
开发者ID:JonasOlson,项目名称:pint,代码行数:11,代码来源:test_contexts.py

示例4: test_defined

# 需要导入模块: from pint.context import Context [as 别名]
# 或者: from pint.context.Context import __keytransform__ [as 别名]
    def test_defined(self):
        ureg = self.ureg
        with ureg.context("sp"):
            pass

        a = Context.__keytransform__(UnitsContainer({"[time]": -1.0}), UnitsContainer({"[length]": 1.0}))
        b = Context.__keytransform__(UnitsContainer({"[length]": 1.0}), UnitsContainer({"[time]": -1.0}))
        self.assertIn(a, ureg._contexts["sp"].funcs)
        self.assertIn(b, ureg._contexts["sp"].funcs)
        with ureg.context("sp"):
            self.assertIn(a, ureg._active_ctx)
            self.assertIn(b, ureg._active_ctx)
开发者ID:JonasOlson,项目名称:pint,代码行数:14,代码来源:test_contexts.py

示例5: test_defined

# 需要导入模块: from pint.context import Context [as 别名]
# 或者: from pint.context.Context import __keytransform__ [as 别名]
    def test_defined(self):
        ureg = self.ureg
        with ureg.context('sp'):
            pass

        a = Context.__keytransform__(UnitsContainer({'[time]': -1.}), UnitsContainer({'[length]': 1.}))
        b = Context.__keytransform__(UnitsContainer({'[length]': 1.}), UnitsContainer({'[time]': -1.}))
        self.assertIn(a, ureg._contexts['sp'].funcs)
        self.assertIn(b, ureg._contexts['sp'].funcs)
        with ureg.context('sp'):
            self.assertIn(a, ureg._active_ctx)
            self.assertIn(b, ureg._active_ctx)
开发者ID:Aircraft-Design-UniNa,项目名称:SUAVE,代码行数:14,代码来源:test_contexts.py

示例6: test_parse_auto_inverse

# 需要导入模块: from pint.context import Context [as 别名]
# 或者: from pint.context.Context import __keytransform__ [as 别名]
    def test_parse_auto_inverse(self):

        a = Context.__keytransform__(UnitsContainer({'[time]': -1.}), UnitsContainer({'[length]': 1.}))
        b = Context.__keytransform__(UnitsContainer({'[length]': 1.}), UnitsContainer({'[time]': -1.}))

        s = ['@context longcontextname',
             '[length] <-> 1 / [time]: c / value']

        c = Context.from_lines(s)
        self.assertEqual(c.defaults, {})
        self.assertEqual(set(c.funcs.keys()), set((a, b)))
        self._test_ctx(c)
开发者ID:Aircraft-Design-UniNa,项目名称:SUAVE,代码行数:14,代码来源:test_contexts.py

示例7: test_parse_parameterized

# 需要导入模块: from pint.context import Context [as 别名]
# 或者: from pint.context.Context import __keytransform__ [as 别名]
    def test_parse_parameterized(self):
        a = Context.__keytransform__(UnitsContainer({"[time]": -1.0}), UnitsContainer({"[length]": 1.0}))
        b = Context.__keytransform__(UnitsContainer({"[length]": 1.0}), UnitsContainer({"[time]": -1.0}))

        s = ["@context(n=1) longcontextname", "[length] <-> 1 / [time]: n * c / value"]

        c = Context.from_lines(s)
        self.assertEqual(c.defaults, {"n": 1})
        self.assertEqual(set(c.funcs.keys()), set((a, b)))
        self._test_ctx(c)

        # If the variable is not present in the definition, then raise an error
        s = ["@context(n=1) longcontextname", "[length] <-> 1 / [time]: c / value"]
        self.assertRaises(ValueError, Context.from_lines, s)
开发者ID:jturner314,项目名称:pint,代码行数:16,代码来源:test_contexts.py

示例8: test_parse_parameterized

# 需要导入模块: from pint.context import Context [as 别名]
# 或者: from pint.context.Context import __keytransform__ [as 别名]
    def test_parse_parameterized(self):
        a = Context.__keytransform__(UnitsContainer({'[time]': -1.}), UnitsContainer({'[length]': 1.}))
        b = Context.__keytransform__(UnitsContainer({'[length]': 1.}), UnitsContainer({'[time]': -1.}))

        s = ['@context(n=1) longcontextname',
             '[length] <-> 1 / [time]: n * c / value']

        c = Context.from_lines(s)
        self.assertEqual(c.defaults, {'n': 1})
        self.assertEqual(set(c.funcs.keys()), set((a, b)))
        self._test_ctx(c)

        s = ['@context(n=1, bla=2) longcontextname',
             '[length] <-> 1 / [time]: n * c / value / bla']

        c = Context.from_lines(s)
        self.assertEqual(c.defaults, {'n': 1, 'bla': 2})
        self.assertEqual(set(c.funcs.keys()), set((a, b)))

        # If the variable is not present in the definition, then raise an error
        s = ['@context(n=1) longcontextname',
             '[length] <-> 1 / [time]: c / value']
        self.assertRaises(ValueError, Context.from_lines, s)
开发者ID:numshub,项目名称:pint,代码行数:25,代码来源:test_contexts.py

示例9: test_spectroscopy

# 需要导入模块: from pint.context import Context [as 别名]
# 或者: from pint.context.Context import __keytransform__ [as 别名]
    def test_spectroscopy(self):
        ureg = self.ureg
        eq = (532.0 * ureg.nm, 563.5 * ureg.terahertz, 2.33053 * ureg.eV)
        with ureg.context("sp"):
            from pint.util import find_shortest_path

            for a, b in itertools.product(eq, eq):
                for x in range(2):
                    if x == 1:
                        a = a.to_base_units()
                        b = b.to_base_units()
                    da, db = Context.__keytransform__(a.dimensionality, b.dimensionality)
                    p = find_shortest_path(ureg._active_ctx.graph, da, db)
                    self.assertTrue(p)
                    msg = "{0} <-> {1}".format(a, b)
                    # assertAlmostEqualRelError converts second to first
                    self.assertQuantityAlmostEqual(b, a, rtol=0.01, msg=msg)

        for a, b in itertools.product(eq, eq):
            self.assertQuantityAlmostEqual(a.to(b.units, "sp"), b, rtol=0.01)
开发者ID:JonasOlson,项目名称:pint,代码行数:22,代码来源:test_contexts.py


注:本文中的pint.context.Context.__keytransform__方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。