{"id":99,"date":"2015-08-10T14:14:57","date_gmt":"2015-08-10T05:14:57","guid":{"rendered":"http:\/\/boltech21.net\/blog\/vottie\/?p=99"},"modified":"2015-09-09T01:21:02","modified_gmt":"2015-09-08T16:21:02","slug":"python-unittest","status":"publish","type":"post","link":"https:\/\/boltech21.net\/blog\/vottie\/?p=99","title":{"rendered":"python\u305d\u306e3 \u30e6\u30cb\u30c3\u30c8\u30c6\u30b9\u30c8"},"content":{"rendered":"<p>python\u3067\u30e6\u30cb\u30c3\u30c8\u30c6\u30b9\u30c8\u3002unittest\u3068\u3044\u3046\u6a5f\u80fd\u304c\u6a19\u6e96\u3067\u5165\u3063\u3066\u308b\u3089\u3057\u3044\u3002\u3057\u304b\u3057\u3001import\u3068from x import y\u306f\u3069\u3046\u3044\u3046\u9806\u5e8f\u3067\u66f8\u304f\u306e\u3060\u308d\u3046?\u3068\u308a\u3042\u3048\u305ac\u306einclude\u3068\u540c\u3058\u3068\u8003\u3048\u3066\u3001\u4ee5\u4e0b\u3067\u66f8\u3044\u3066\u307f\u308b\u3002<\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">import unittest\r\nfrom calc import Calc<\/pre>\n<p>\u30e6\u30cb\u30c3\u30c8\u30c6\u30b9\u30c8\u3092\u3053\u3055\u3048\u305f\u6642\u70b9\u3067\u3053\u3093\u306a\u611f\u3058\u306b\u306a\u3063\u305f\u3002<\/p>\n<p><a href=\"https:\/\/github.com\/vottie\/lang\/blob\/0b445c9606d30f31a6df1d99ef4d564f931014f2\/python\/calc\/calc_test.py\" target=\"_blank\">calc_test.py<\/a><\/p>\n<p>\u81ea\u4f5c\u306eCalc\u30af\u30e9\u30b9\u306eadd()\u306f\u3001\u5f15\u6570\u3068\u3057\u3066x\u3068y\u3092\u53d6\u308b\u3002x\u3068y\u306f\u6574\u6570\u578b\u3092\u671f\u5f85\u3057\u3066\u308b\u3093\u3060\u3051\u3069\u3001\u691c\u8a3c\u306f\u5168\u304f\u3084\u3063\u3066\u306a\u3044\u3093\u3067\u3001\u5f15\u6570\u3092\u691c\u8a3c\u3059\u308b\u51e6\u7406\u3092\u8ffd\u52a0\u3057\u3066\u3001\u30c6\u30b9\u30c8\u30b1\u30fc\u30b9\u3092\u8ffd\u52a0\u3067\u66f8\u3044\u305f\u306e\u304c\u4ee5\u4e0b\u3002<\/p>\n<p><a href=\"https:\/\/github.com\/vottie\/lang\/commit\/3cfb19a0ec4d886e20559a39474dd9baaa890f40#diff-7d3ee90cc80da3902613080da1b83be0\" target=\"_blank\">\u5f15\u6570\u30c1\u30a7\u30c3\u30af\u8ffd\u52a0<\/a><\/p>\n<p>\u30c7\u30fc\u30bf\u578b\u306e\u5909\u63db\u306b\u3064\u3044\u3066\u306f<\/p>\n<p><a href=\"http:\/\/kwatch.houkagoteatime.net\/blog\/2014\/08\/24\/python-pitfalls\/\" target=\"_blank\">\u7d30\u304b\u3059\u304e\u3066\u4f1d\u308f\u308a\u306b\u304f\u3044\u3001Python\u306e\u672c\u5f53\u306e\u843d\u3068\u3057\u7a7410\u9078(\u79c1\u306e\u5c0f\u5ca9\u30db\u30c3\u30c1\u30ad\u30b9)<\/a>\u3001\u4f8b\u5916\u306e\u30c6\u30b9\u30c8\u306e\u3084\u308a\u65b9\u306f<a href=\"http:\/\/kannokanno.hatenablog.com\/entry\/20130501\/1367408912\" target=\"_blank\">Python &#8211; unittest\u306eassertRaises\u306e\u4f7f\u3044\u65b9(\u307c\u3063\u3061\u52c9\u5f37\u4f1a)<\/a>\u3092\u53c2\u8003\u306b\u3055\u305b\u3066\u3044\u305f\u3060\u304d\u307e\u3057\u305f\u3002<\/p>\n<p>\u3055\u3089\u306b\u8ffd\u52a0\u30c6\u30b9\u30c8\u3002\u500b\u3005\u306e\u5024\u306e\u691c\u8a3c\u306f\u3067\u304d\u305f\u3068\u3057\u3066\u3001\u6700\u5927\u5024+1\u3057\u305f\u3089\u3069\u3046\u306a\u308b\u304b\u3001int\u578b\u3068\u3057\u3066\u8d85\u3048\u3061\u3083\u3046\u304b\u3089\u5b9f\u884c\u6642\u4f8b\u5916\u304c\u767a\u751f\u3059\u308b\u304b\u306a\u3068\u601d\u3063\u305f\u3051\u3069\u3001\u3067\u304d\u3061\u3083\u3063\u305f\u2026\u8fd4\u308a\u5024\u306e\u30c7\u30fc\u30bf\u578b\u304cint\u3058\u3083\u306a\u304f\u3066long\u3067\u5e30\u3063\u305f\u3093\u3060\u308d\u3046\u304b?<\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\"> def test_add_max(self):\r\nc = Calc()\r\nx = sys.maxint\r\ny = 1\r\nresult = 0\r\nresult = c.add(x,y)\r\nprint '{0} + {1} = {2}'.format(x, y, result)\r\nself.assertEqual(x + y, result)\r\n\r\n<\/pre>\n<p>\u5b9f\u884c\u7d50\u679c\u3002<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\n\r\n$ python calc_test.py\r\nCalc Test\r\n100 + 200 = 300\r\n.Calc Test\r\n9223372036854775807 + 1 = 9223372036854775808\r\n.Calc Test\r\n.\r\n----------------------------------------------------------------------\r\nRan 3 tests in 0.001s\r\n\r\nOK\r\n$\r\n\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>python\u3067\u30e6\u30cb\u30c3\u30c8\u30c6\u30b9\u30c8\u3002unittest\u3068\u3044\u3046\u6a5f\u80fd\u304c\u6a19\u6e96\u3067\u5165\u3063\u3066\u308b\u3089\u3057\u3044\u3002\u3057\u304b\u3057\u3001import\u3068from x import y\u306f\u3069\u3046\u3044\u3046\u9806\u5e8f\u3067\u66f8\u304f\u306e\u3060\u308d\u3046?\u3068\u308a\u3042\u3048\u305ac\u306einclude\u3068\u540c\u3058\u3068\u8003\u3048\u3066\u3001\u4ee5\u4e0b\u3067\u66f8\u3044\u3066\u307f\u308b\u3002 import unittest from calc import Calc \u30e6\u30cb\u30c3\u30c8\u30c6\u30b9\u30c8\u3092\u3053\u3055\u3048\u305f\u6642\u70b9\u3067\u3053\u3093\u306a\u611f\u3058\u306b\u306a\u3063\u305f\u3002 calc_test.py \u81ea\u4f5c\u306eCalc\u30af\u30e9\u30b9\u306eadd()\u306f\u3001\u5f15\u6570\u3068\u3057\u3066x\u3068y\u3092\u53d6\u308b\u3002x\u3068y\u306f\u6574\u6570\u578b\u3092\u671f\u5f85\u3057\u3066\u308b\u3093\u3060\u3051\u3069\u3001\u691c\u8a3c\u306f\u5168\u304f\u3084\u3063\u3066\u306a\u3044\u3093\u3067\u3001\u5f15\u6570\u3092\u691c\u8a3c\u3059\u308b\u51e6\u7406\u3092\u8ffd\u52a0\u3057\u3066\u3001\u30c6\u30b9\u30c8\u30b1\u30fc\u30b9\u3092\u8ffd\u52a0\u3067\u66f8\u3044\u305f\u306e\u304c\u4ee5\u4e0b\u3002 \u5f15\u6570\u30c1\u30a7\u30c3\u30af\u8ffd\u52a0 \u30c7\u30fc\u30bf\u578b\u306e\u5909\u63db\u306b\u3064\u3044\u3066\u306f \u7d30\u304b\u3059\u304e\u3066\u4f1d\u308f\u308a\u306b\u304f\u3044\u3001Python\u306e\u672c\u5f53\u306e\u843d\u3068\u3057\u7a7410\u9078(\u79c1\u306e\u5c0f\u5ca9\u30db\u30c3\u30c1\u30ad\u30b9)\u3001\u4f8b\u5916\u306e\u30c6\u30b9\u30c8\u306e\u3084\u308a\u65b9\u306fPython &#8211; unittest\u306eassertRaises\u306e\u4f7f\u3044\u65b9(\u307c\u3063\u3061\u52c9\u5f37\u4f1a)\u3092\u53c2\u8003\u306b\u3055\u305b\u3066\u3044\u305f\u3060\u304d\u307e\u3057\u305f\u3002 \u3055\u3089\u306b\u8ffd\u52a0\u30c6\u30b9\u30c8\u3002\u500b\u3005\u306e\u5024\u306e\u691c\u8a3c\u306f\u3067\u304d\u305f\u3068\u3057\u3066\u3001\u6700\u5927\u5024+1\u3057\u305f\u3089\u3069\u3046\u306a\u308b\u304b\u3001int\u578b\u3068\u3057\u3066\u8d85\u3048\u3061\u3083\u3046\u304b\u3089\u5b9f\u884c\u6642\u4f8b\u5916\u304c\u767a\u751f\u3059\u308b\u304b\u306a\u3068\u601d\u3063\u305f\u3051\u3069\u3001\u3067\u304d\u3061\u3083\u3063\u305f\u2026\u8fd4\u308a\u5024\u306e\u30c7\u30fc\u30bf\u578b\u304cint\u3058\u3083\u306a\u304f\u3066long\u3067\u5e30\u3063\u305f\u3093\u3060\u308d\u3046\u304b? def test_add_max(self): c = Calc() x = sys.maxint y = 1 result = 0 result = c.add(x,y) print &#8216;{0} + {1} = {2}&#8217;.format(x, y, result) self.assertEqual(x + y, result) \u5b9f\u884c\u7d50\u679c\u3002 $ python calc_test.py Calc Test 100 + 200 = 300 .Calc Test 9223372036854775807 + 1 = 9223372036854775808 .Calc Test . &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;- Ran 3 tests in 0.001s OK $<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[6],"tags":[8,11],"class_list":["post-99","post","type-post","status-publish","format-standard","hentry","category-computer","tag-python","tag-unittest"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p4Yc9l-1B","_links":{"self":[{"href":"https:\/\/boltech21.net\/blog\/vottie\/index.php?rest_route=\/wp\/v2\/posts\/99","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/boltech21.net\/blog\/vottie\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/boltech21.net\/blog\/vottie\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/boltech21.net\/blog\/vottie\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/boltech21.net\/blog\/vottie\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=99"}],"version-history":[{"count":4,"href":"https:\/\/boltech21.net\/blog\/vottie\/index.php?rest_route=\/wp\/v2\/posts\/99\/revisions"}],"predecessor-version":[{"id":104,"href":"https:\/\/boltech21.net\/blog\/vottie\/index.php?rest_route=\/wp\/v2\/posts\/99\/revisions\/104"}],"wp:attachment":[{"href":"https:\/\/boltech21.net\/blog\/vottie\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=99"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/boltech21.net\/blog\/vottie\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=99"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/boltech21.net\/blog\/vottie\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=99"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}