• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python builtins.create_builtins_module函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中modules.builtins.create_builtins_module函数的典型用法代码示例。如果您正苦于以下问题:Python create_builtins_module函数的具体用法?Python create_builtins_module怎么用?Python create_builtins_module使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



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

示例1: test_w_when_no_exception_in_code_then_handler_not_triggered

    def test_w_when_no_exception_in_code_then_handler_not_triggered(self):
        # when
        result = eval_str('''(try
                                "code"
                             (except
                                "exc")
                             (finally
                                "fin"))''',
                          create_builtins_module())
        # then
        self.assertIsInstance(result, WString)
        self.assertEqual("code", result)
        # when
        result = eval_str('''(try
                                "code"
                             (except
                                "exc"))''',
                          create_builtins_module())
        # then
        self.assertIsInstance(result, WString)
        self.assertEqual("code", result)

        # when
        result = eval_str('''(try
                                "code"
                             (except
                                (raise "exc")))''',
                          create_builtins_module())
        # then
        self.assertIsInstance(result, WString)
        self.assertEqual("code", result)
开发者ID:izrik,项目名称:wodehouse,代码行数:31,代码来源:try_tests.py


示例2: test_mult_mults_numbers

 def test_mult_mults_numbers(self):
     # when
     result = mult(WNumber(1), WNumber(2), WNumber(3), WNumber(4))
     # then
     self.assertIsInstance(result, WNumber)
     self.assertEqual(24, result)
     # when
     result = eval_str("(* 1 2 3 4)", create_builtins_module())
     # then
     self.assertIsInstance(result, WNumber)
     self.assertEqual(24, result)
     # when
     result = mult(WNumber(3), WNumber(2))
     # then
     self.assertIsInstance(result, WNumber)
     self.assertEqual(6, result)
     # when
     result = eval_str("(* 3 2)", create_builtins_module())
     # then
     self.assertIsInstance(result, WNumber)
     self.assertEqual(6, result)
     # when
     result = mult(WNumber(5), WNumber(2))
     # then
     self.assertIsInstance(result, WNumber)
     self.assertEqual(10, result)
     # when
     result = eval_str("(* 5 2)", create_builtins_module())
     # then
     self.assertIsInstance(result, WNumber)
     self.assertEqual(10, result)
开发者ID:izrik,项目名称:wodehouse,代码行数:31,代码来源:mult_tests.py


示例3: test_w_exception_in_finally_overrides_retval_in_code

 def test_w_exception_in_finally_overrides_retval_in_code(self):
     # when
     result = eval_str('''(try
                             "code"
                          (except
                             "exc")
                          (finally
                             (raise "fin")))''',
                       create_builtins_module())
     # then
     self.assertIsInstance(result, WRaisedException)
     self.assertIsInstance(result.exception, WException)
     self.assertEqual("fin", result.exception.message)
     # when
     result = eval_str('''(try
                             "code"
                          (except
                             (raise "exc"))
                          (finally
                             (raise "fin")))''',
                       create_builtins_module())
     # then
     self.assertIsInstance(result, WRaisedException)
     self.assertIsInstance(result.exception, WException)
     self.assertEqual("fin", result.exception.message)
     # when
     result = eval_str('''(try
                             "code"
                          (finally
                             (raise "fin")))''',
                       create_builtins_module())
     # then
     self.assertIsInstance(result, WRaisedException)
     self.assertIsInstance(result.exception, WException)
     self.assertEqual("fin", result.exception.message)
开发者ID:izrik,项目名称:wodehouse,代码行数:35,代码来源:try_tests.py


示例4: test_sub_subs_numbers

 def test_sub_subs_numbers(self):
     # when
     result = sub(WNumber(1), WNumber(2), WNumber(3), WNumber(4))
     # then
     self.assertIsInstance(result, WNumber)
     self.assertEqual(-8, result)
     # when
     result = eval_str("(- 1 2 3 4)", create_builtins_module())
     # then
     self.assertIsInstance(result, WNumber)
     self.assertEqual(-8, result)
     # when
     result = sub(WNumber(3), WNumber(2))
     # then
     self.assertIsInstance(result, WNumber)
     self.assertEqual(1, result)
     # when
     result = eval_str("(- 3 2)", create_builtins_module())
     # then
     self.assertIsInstance(result, WNumber)
     self.assertEqual(1, result)
     # when
     result = sub(WNumber(5), WNumber(1), WNumber(1))
     # then
     self.assertIsInstance(result, WNumber)
     self.assertEqual(3, result)
     # when
     result = eval_str("(- 5 1 1)", create_builtins_module())
     # then
     self.assertIsInstance(result, WNumber)
     self.assertEqual(3, result)
开发者ID:izrik,项目名称:wodehouse,代码行数:31,代码来源:sub_tests.py


示例5: test_get_gets_value_by_key

 def test_get_gets_value_by_key(self):
     # when
     result = eval_str("(get (new_scope '((a 1) (b 2))) 'a)",
                       create_builtins_module())
     # then
     self.assertEqual(1, result)
     # when
     result = eval_str("(get (new_scope '((a 1) (b 2))) 'b)",
                       create_builtins_module())
     # then
     self.assertEqual(2, result)
开发者ID:izrik,项目名称:wodehouse,代码行数:11,代码来源:get_scope_value_tests.py


示例6: test_or_returns_true_if_any_true

 def test_or_returns_true_if_any_true(self):
     # when
     result = eval_str("(or false true)", create_builtins_module())
     # then
     self.assertIs(WBoolean.true, result)
     # when
     result = eval_str("(or true false)", create_builtins_module())
     # then
     self.assertIs(WBoolean.true, result)
     # when
     result = eval_str("(or true true)", create_builtins_module())
     # then
     self.assertIs(WBoolean.true, result)
开发者ID:izrik,项目名称:wodehouse,代码行数:13,代码来源:w_or_tests.py


示例7: test_and_returns_false_if_any_false

 def test_and_returns_false_if_any_false(self):
     # when
     result = eval_str("(and false true)", create_builtins_module())
     # then
     self.assertIs(WBoolean.false, result)
     # when
     result = eval_str("(and true false)", create_builtins_module())
     # then
     self.assertIs(WBoolean.false, result)
     # when
     result = eval_str("(and false false)", create_builtins_module())
     # then
     self.assertIs(WBoolean.false, result)
开发者ID:izrik,项目名称:wodehouse,代码行数:13,代码来源:w_and_tests.py


示例8: test_maps_with_named_function

 def test_maps_with_named_function(self):
     # when
     result = eval_str(
         "(map car '((1 2 3) (a b c) (\"a\" \"b\" \"c\")))",
         create_builtins_module())
     # then
     self.assertEqual([1, WSymbol.get('a'), 'a'], result)
开发者ID:izrik,项目名称:wodehouse,代码行数:7,代码来源:map_tests.py


示例9: test_str_strings_are_unchanged

 def test_str_strings_are_unchanged(self):
     # when
     result = eval_str("(str \"123\")", create_builtins_module())
     # then
     self.assertIsInstance(result, WString)
     self.assertIsInstance(result.value, str)
     self.assertEqual("123", result)
开发者ID:izrik,项目名称:wodehouse,代码行数:7,代码来源:w_str_tests.py


示例10: test_str_stringifies_quoted_symbols

 def test_str_stringifies_quoted_symbols(self):
     # when
     result = eval_str("(str ''asdf)", create_builtins_module())
     # then
     self.assertIsInstance(result, WString)
     self.assertIsInstance(result.value, str)
     self.assertEqual("'asdf", result)
开发者ID:izrik,项目名称:wodehouse,代码行数:7,代码来源:w_str_tests.py


示例11: test_str_stringifies_magic_functions

 def test_str_stringifies_magic_functions(self):
     # when
     result = eval_str("(str str)", create_builtins_module())
     # then
     self.assertIsInstance(result, WString)
     self.assertIsInstance(result.value, str)
     self.assertEqual("str", result)
开发者ID:izrik,项目名称:wodehouse,代码行数:7,代码来源:w_str_tests.py


示例12: test_call_nested_macro_returns_empty_list

 def test_call_nested_macro_returns_empty_list(self):
     # when
     result = eval_str("(if true (if true '() 2) 3)",
                       create_builtins_module())
     # then
     self.assertIsInstance(result, WList)
     self.assertEqual([], result)
开发者ID:izrik,项目名称:wodehouse,代码行数:7,代码来源:misc_macro_tests.py


示例13: test_get_next_char_after_end_of_stream_raises

 def test_get_next_char_after_end_of_stream_raises(self):
     # expect
     self.assertRaisesRegex(
         Exception,
         "No more characters in the stream.",
         eval_str,
         "(get_next_char (stream \"\"))", create_builtins_module())
开发者ID:izrik,项目名称:wodehouse,代码行数:7,代码来源:stream_get_next_char_tests.py


示例14: test_format_interpolates_arguments

 def test_format_interpolates_arguments(self):
     # when
     result = eval_str("(format \"one {} three\" \"two\")",
                       create_builtins_module())
     # then
     self.assertIsInstance(result, WString)
     self.assertEqual("one two three", result)
开发者ID:izrik,项目名称:wodehouse,代码行数:7,代码来源:w_format_tests.py


示例15: test_get_next_char_gets_next_char

 def test_get_next_char_gets_next_char(self):
     # when
     result = eval_str("(get_next_char (stream \"abc\"))",
                       create_builtins_module())
     # then
     self.assertIsInstance(result, WString)
     self.assertEqual("a", result)
开发者ID:izrik,项目名称:wodehouse,代码行数:7,代码来源:stream_get_next_char_tests.py


示例16: test_map_empty_list_yields_empty_list

 def test_map_empty_list_yields_empty_list(self):
     # given
     bm = create_builtins_module()
     # when
     result = eval_str("(map (lambda (x) (* x x)) '())", bm)
     # then
     self.assertEqual([], result)
开发者ID:izrik,项目名称:wodehouse,代码行数:7,代码来源:map_tests.py


示例17: test_str_stringifies_boolean_variable

 def test_str_stringifies_boolean_variable(self):
     # when
     result = eval_str("(let (a true) (str a))", create_builtins_module())
     # then
     self.assertIsInstance(result, WString)
     self.assertIsInstance(result.value, str)
     self.assertEqual("true", result)
开发者ID:izrik,项目名称:wodehouse,代码行数:7,代码来源:w_str_tests.py


示例18: test_str_stringifies_boolean_false

 def test_str_stringifies_boolean_false(self):
     # when
     result = eval_str("(str false)", create_builtins_module())
     # then
     self.assertIsInstance(result, WString)
     self.assertIsInstance(result.value, str)
     self.assertEqual("false", result)
开发者ID:izrik,项目名称:wodehouse,代码行数:7,代码来源:w_str_tests.py


示例19: test_str_stringifies_numbers

 def test_str_stringifies_numbers(self):
     # when
     result = eval_str("(str 123)", create_builtins_module())
     # then
     self.assertIsInstance(result, WString)
     self.assertIsInstance(result.value, str)
     self.assertEqual("123", result)
开发者ID:izrik,项目名称:wodehouse,代码行数:7,代码来源:w_str_tests.py


示例20: test_exception_in_callee_triggers_handler

 def test_exception_in_callee_triggers_handler(self):
     # given
     s = create_builtins_module()
     calls = []
     mkfunc('a', calls, s)
     mkfunc('b', calls, s)
     mkfunc('c', calls, s)
     mkfunc('d', calls, s)
     mkfunc('e', calls, s)
     x = eval_str('(def x () (raise "asdf"))', s)
     y = eval_str('(def y () ((x) (b) 2 3 4))', s)
     # precondition
     self.assertIsNotNone(x)
     self.assertIsNotNone(y)
     # when
     result = eval_str("""(try
                             (exec
                                 (a)
                                 (y)
                                 (c))
                          (except
                             (exec
                                 (d)
                                 "exc"))
                          (finally
                             (exec
                                 (e)
                                 "fin")))""", s)
     # then
     self.assertIsInstance(result, WString)
     self.assertEqual("exc", result)
     # and
     self.assertEqual(['a', 'd', 'e'], calls)
开发者ID:izrik,项目名称:wodehouse,代码行数:33,代码来源:try_tests.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python client.agent函数代码示例发布时间:2022-05-27
下一篇:
Python blankspace.remove_whitespaces函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap