More Related Content
Similar to ユニットテストと始める始める安全なPythonライブラリ開発
Similar to ユニットテストと始める始める安全なPythonライブラリ開発 (20)
ユニットテストと始める始める安全なPythonライブラリ開発
- 2. お前、誰よ
• ひやかし (Yuya Oka)
• 宇部⾼専 経営情報学科卒
• 社会⼈2年⽬
• Pythonista(笑) & iOS Engineer
• https://now.kibousoft.co.jp/@nnsnodnb
• and so on.
- 29. class Hoge(object):
def __init__(self, value=None):
self.value = value
def __str__(self):
return self.value
if __name__ == '__main__':
hoge = Hoge(value='hoge foo bar')
print(hoge)
hoge.py
- 30. import unittest
from hoge import Hoge
class HogeTest(unittest.TestCase):
def setUp(self):
self.hoge = Hoge()
def tearDown(self):
self.hoge = None
- 31. def test_is_value(self):
self.hoge.value = 'test'
self.assertEqual(str(self.hoge), 'test')
self.assertEqual(self.hoge.__str__(), 'test')
def test_none_value(self):
with self.assertRaises(TypeError):
print(self.hoge)
if __name__ == '__main__':
unittest.main()