软件工程第二次作业 - 用python unittest 模块进行单元测试
用python unittest
模块进行单元测试
环境
-
语言: python 2.7
-
集成开发环境: PyCharm 2017.3
-
操作系统: Arch Linux 内核版本 4.15.10
测试项目
AmazonEdge
一个模仿AlphaGo
实现的基于卷积神经网络,借助监督式学习的亚马逊棋AI,源码托管在GitHub
测试用例
import os
from AmazonEdge.training.supervised_policy_trainer import run_training
import unittest
class TestSupervisedPolicyTrainer(unittest.TestCase):
def testTrain(self):
model = 'tests/test_data/model.json'
data = 'tests/test_data/hdf5/very_weak.hdf5'
output = 'tests/test_data/.tmp.training/'
args = [model, data, output, '--verbose', '--epochs', '1']
run_training(args)
os.remove(os.path.join(output, 'metadata.json'))
os.remove(os.path.join(output, 'shuffle.npz'))
os.remove(os.path.join(output, 'weights.00000.hdf5'))
os.rmdir(output)
if __name__ == '__main__':
unittest.main()
测试类TestSupervisedPolicyTrainer
从unittest.TestCase
继承,测试方法为testTrain
,是对training
模块的run_training
方法进行测试。
指定测试用的模型为tests/test_data/
路径下的model.json
,测试用数据为 tests/test_data/hdf5/
路径下的very_weak.hdf5
文件,训练产生的权重文件输出到tests/test_data/.tmp.training/
路径,训练批次epochs
指定为1。
测试过程
在AmazonEdge
根目录下键入命令:
python -m tests.test_supervised_policy_trainer
得到结果:
表示测试通过。