本文整理汇总了Python中pint.context.Context.from_lines方法的典型用法代码示例。如果您正苦于以下问题:Python Context.from_lines方法的具体用法?Python Context.from_lines怎么用?Python Context.from_lines使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pint.context.Context
的用法示例。
在下文中一共展示了Context.from_lines方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_parse_simple
# 需要导入模块: from pint.context import Context [as 别名]
# 或者: from pint.context.Context import from_lines [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)
示例2: test_parse_simple
# 需要导入模块: from pint.context import Context [as 别名]
# 或者: from pint.context.Context import from_lines [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)
示例3: test_parse_define
# 需要导入模块: from pint.context import Context [as 别名]
# 或者: from pint.context.Context import from_lines [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)
示例4: test_parse_parameterized
# 需要导入模块: from pint.context import Context [as 别名]
# 或者: from pint.context.Context import from_lines [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)
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)
示例5: test_parse_auto_inverse
# 需要导入模块: from pint.context import Context [as 别名]
# 或者: from pint.context.Context import from_lines [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)
示例6: test_parse_parameterized
# 需要导入模块: from pint.context import Context [as 别名]
# 或者: from pint.context.Context import from_lines [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)
# 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)