python 单元测试


A test­case is cre­at­ed by sub­class­ing unittest.TestCase. The three indi­vid­u­al tests are defined with meth­ods whose names start with the let­ters test. This nam­ing con­ven­tion informs the test run­ner about which meth­ods rep­re­sent tests.

The crux of each test is a call to assertE­qual() to check for an expect­ed result; assert­True() or assert­False() to ver­i­fy a con­di­tion; or asser­tRais­es() to ver­i­fy that a speci­fic excep­tion gets raised. The­se meth­ods are used instead of the assert state­ment so the test run­ner can accu­mu­late all test results and pro­duce a report.

The setUp() and tear­Down() meth­ods allow you to define instruc­tions that will be exe­cut­ed before and after each test method. They are cov­ered in more detail in the sec­tion Orga­niz­ing test code.

The final block shows a sim­ple way to run the tests. unittest.main() pro­vides a com­mand-line inter­face to the test script. When run from the com­mand line, the above script pro­duces an out­put that looks like this:

PCA — 数据降维


新数据,2维:(5,0), (10,0)

最终简化为一维:5, 10



relat­ed posts:







1. 提交

git add .

git com­mit –m “your com­ments about this sub­mis­sion”

git push orig­in mas­ter

2. 下载