Pythonã§setup.pyã使ã£ã¦ãã¹ãããå ´åã®ãã©ã«ãæ§æ
å°ãåãããªãã£ãã®ã§ãåå¿é²ã¨ãã¦æ¸ãã¦ããã
pythonã§srcã¨testãã©ã«ããåãã¦ããå ´åãä¸æããã¹ããåºæ¥ãªãã£ãã®ã§ãè²ã 調ã¹ã¦ã¿ãã
ãã©ã«ãæ§æ
ç§ãä½ã£ããã©ã«ãã¯ä¸è¨ã®ãããªæ§æã
./Sample |--/src ・・・å®è¡ç¨ã¹ã¯ãªãã | |--/test ・・・ãã¹ãã¹ã¯ãªãã | |--setup.py
setup.pyã¯Javaã§ããã¨ãbuild.xmlãpom.xmlã¿ãããªãã®ã
python setup.py test
ã¨ã³ãã³ããæã¤ã¨ããã¹ããå®è¡ãã¦ããã¾ãã
setup.pyã使ã£ãç°¡åãªãã¹ãä¾
ã¾ãããã©ã«ãã»ã½ã¼ã¹æ§æã¯ä¸è¨ã®éã
./Sample |--/src | |--__init__.py | |--sample.py |--/test | |--sample_test.py |--setup.py
__init__.py
from sample import *
__init__.pyã¯ããã ãOKã
sample.py
#!/usr/bin/env python # -*- coding:utf-8 -*- class Calc: def add(self, x, y): return x+y
åãç°¡åãªä¾ã§ãã
説æã¯çç¥ã
sample_test.py
#!/usr/bin/env python # -*- coding:utf-8 import unittest from sample import Calc class TestSample(unittest.TestCase): def test_sample(self): calc = Calc() self.assertEqual(15, calc.add(10, 5)) def suite(): suite = unittest.TestSuite() suite.addTests(unittest.makeSuite(TestSample)) return suite
ãããunittestã®ç°¡åãªä¾ã§ãã
TestCaseãç¶æ¿ããã¯ã©ã¹ãä½æãããã¹ãã±ã¼ã¹ãä½æãã¦ãã¾ãã
suite()ã¡ã½ããã§ãã¹ãã±ã¼ã¹ãTestSuiteã«è¿½å ãã¦ãã¾ãã
setup.py
from setuptools import setup, find_packages import sys sys.path.append('./src') sys.path.append('./test') setup( name = "Sample", version = "0.1", packages = find_packages(), test_suite = 'sample_test.suite' )
éè¦ãªã®ã¯ãï¼ã¤ã®ãã©ã«ãããã¹ã«è¿½å ããã¨ããã
import sys sys.path.append('./src') sys.path.append('./test')
ããããªãã¨"No module named sample_test"ã¨åºã¦ãã¾ãããã¹ããå®è¡ã§ãã¾ããã
ããã¦ãtest_suiteã®æå®ã
test_suite = 'sample_test.suite'
ããã§TestSuiteãè¨å®ãã¦ããã¾ãã
ãã¹ãã®å®è¡
ãã®æ§æã§ãã¹ããå®è¡ãã¦ã¿ãã¨ããã¹ããå®è¡ããã¦ããã®ãåããã¾ãã
C:\Sample>python setup.py test running test running egg_info writing Sample.egg-info\PKG-INFO writing top-level names to Sample.egg-info\top_level.txt writing dependency_links to Sample.egg-info\dependency_links.txt reading manifest file 'Sample.egg-info\SOURCES.txt' writing manifest file 'Sample.egg-info\SOURCES.txt' running build_ext test_sample (sample_test.TestSample) ... ok ---------------------------------------------------------------------- Ran 1 test in 0.000s OK
ãã¡ã¤ã«ä¸å¼
試ã人ããããåãããªããã©ãä¸å¿Dropboxã«ä¸ãã¦ããã¾ãã
setuppy.zip