Skip to content

Instantly share code, notes, and snippets.

# -*- coding:utf-8 -*-
import unittest
import your_logic as logic
class LogicTest(unittest.TestCase):
def test_logic(self):
self.assertEquals('expect', logic.do_logic())
if __name__ == '__main__':
@reiki4040
reiki4040 / your_logic.py
Created September 8, 2013 03:20
example for unit test.
# -*- coding:utf-8 -*-
def do_logic():
# your logic
return 'expect'
@reiki4040
reiki4040 / sqs_example.py
Created July 13, 2013 11:11
example for Amazon SQS
# -*- coding:utf-8 -*-
import time
import sys
import boto.sqs
from boto.sqs.message import Message
# tokyo region
DEFAULT_REGION = 'ap-northeast-1'
Q_NAME = 'myqueue'
@reiki4040
reiki4040 / ExampleWithClass.py
Last active May 19, 2019 09:30
Example Python with statement 2013/8/24 fix LABEL comment at main(). LABEL was different to explain on blog. http://d.hatena.ne.jp/reiki4040/20130331/1364723288
class ExampleWithClass:
def __init__(self):
print('__init__')
def __del__(self):
print('__del__')
def __enter__(self):
print('__enter__')
#raise ValueError # [LABEL C]
@reiki4040
reiki4040 / gist:5004644
Created February 21, 2013 13:11
fluent-plugin-parserにテスト追加中。 pattern not matchメッセージがとれない。。。標準出力、エラーではなく別の場所に出てるのかな。 pluginの中で、$log.warn で出してるところを取りたい。
def capture_stderr(&block)
original = $stderr
captured = $stderr = StringIO.new
begin
yield
ensure
$stderr = original
end
@reiki4040
reiki4040 / kurume_temp2gf.py
Created February 4, 2013 13:26
get temperture and send growthforecast.
# -*- coding:utf-8 -*-
import json
import urllib3
def get_temperature(http):
# city=400040 Kurume city in Fukuoka.
resp = http.request('GET', 'http://weather.livedoor.com/forecast/webservice/json/v1?city=400040')
json_data = json.loads(resp.data.decode('utf-8'))