Rename test cases from 'test*()' format to '*test()' format

This commit is contained in:
LeoHsiao 2020-08-27 23:12:10 +08:00
parent ca06206f50
commit b6bf32bd5f
3 changed files with 57 additions and 30 deletions

View File

@ -16,7 +16,7 @@ class TestCases(unittest.TestCase):
pass
def test_addmoddel(self):
def addmoddel_test(self):
# Test driver to run the addmoddel sample program
jpg = 'exiv2-empty.jpg'
BT.copyTestFile(jpg)
@ -26,7 +26,7 @@ class TestCases(unittest.TestCase):
BT.reportTest('addmoddel', out)
def test_conversions(self):
def conversions_test(self):
# XMP parser test driver
jpg = 'exiv2-empty.jpg'
out = BT.Output()
@ -234,7 +234,7 @@ class TestCases(unittest.TestCase):
BT.reportTest('conversions', out)
def test_crw(self):
def crw_test(self):
# Test driver for CRW file operations
crwfile = 'exiv2-canon-powershot-s40.crw'
@ -268,7 +268,7 @@ set Exif.Photo.DateTimeDigitized 2020:05:26 07:31:42'''
BT.reportTest('crw-test', out)
def test_exifdata(self):
def exifdata_test(self):
# Test driver for exifdata copy construction and assignment unit tests
out = BT.Output()
for jpg in ['exiv2-gc.jpg', 'exiv2-canon-powershot-s40.jpg', 'exiv2-nikon-d70.jpg']:
@ -277,7 +277,7 @@ set Exif.Photo.DateTimeDigitized 2020:05:26 07:31:42'''
BT.reportTest('exifdata-test', out)
def test_exiv2(self):
def exiv2_test(self):
# Add each image to the following three lists.
# The image basename in the second and third lists
# is the Exif timestamp adjusted by -12:01:01.
@ -409,7 +409,7 @@ set Exif.Photo.DateTimeDigitized 2020:05:26 07:31:42'''
BT.reportTest('exiv2-test', out)
def test_geotag(self):
def geotag_test(self):
# Test driver for geotag
jpg = 'FurnaceCreekInn.jpg'
gpx = 'FurnaceCreekInn.gpx'
@ -437,7 +437,7 @@ set Exif.Photo.DateTimeDigitized 2020:05:26 07:31:42'''
BT.reportTest('geotag-test', out)
def test_icc(self):
def icc_test(self):
# Test driver for exiv2.exe ICC support (-pS, -pC, -eC, -iC)
def test1120(img):
@ -502,7 +502,7 @@ set Exif.Photo.DateTimeDigitized 2020:05:26 07:31:42'''
BT.reportTest('icc-test', out)
def test_image(self):
def image_test(self):
test_files = [
'table.jpg',
'smiley1.jpg',
@ -563,7 +563,7 @@ set Exif.Photo.DateTimeDigitized 2020:05:26 07:31:42'''
# BT.reportTest('imagetest', out)
def test_io(self):
def io_test(self):
# Test driver for file i/o
test_files = ['table.jpg', 'smiley2.jpg', 'ext.dat']
for f in test_files:
@ -576,10 +576,11 @@ set Exif.Photo.DateTimeDigitized 2020:05:26 07:31:42'''
result += [BT.md5sum(i) for i in files]
return ' '.join(result)
server_bind = '127.0.0.1'
server_port = 12760
server_url = 'http://{}:{}'.format(server_bind, server_port)
server = BT.HttpServer(bind=server_bind, port=server_port, work_dir=os.path.join(BT.Config.data_dir))
server_url = 'http://{}:{}'.format(BT.Config.http_server_bind,
BT.Config.http_server_port)
server = BT.HttpServer(bind=BT.Config.http_server_bind,
port=BT.Config.http_server_port,
work_dir=os.path.join(BT.Config.data_dir))
try:
server.start()
out = BT.Output()

View File

@ -24,9 +24,11 @@ class Config:
""" Init test environments and variables """
os.makedirs(cls.tmp_dir, exist_ok=True)
os.chdir(cls.tmp_dir)
log.buffer = []
cls.bin_files = [i.split('.')[0] for i in os.listdir(cls.bin_dir)]
cls.encoding = 'utf-8'
log.buffer = []
cls.bin_files = [i.split('.')[0] for i in os.listdir(cls.bin_dir)]
cls.encoding = 'utf-8'
cls.http_server_bind = '127.0.0.1'
cls.http_server_port = 12760
class Log:

View File

@ -1,16 +1,39 @@
# -*- coding: utf-8 -*-
import argparse
import functools
import os
import sys
import unittest
from fnmatch import fnmatchcase
import system_tests
class MyTestLoader(unittest.TestLoader):
testNamePatterns = None
def getTestCaseNames(self, testCaseClass):
"""
Customize this code to allow you to filter test methods through testNamePatterns.
"""
def shouldIncludeMethod(attrname):
if not attrname.startswith(self.testMethodPrefix):
return False
testFunc = getattr(testCaseClass, attrname)
if not callable(testFunc):
return False
return self.testNamePatterns is None or \
any(fnmatchcase(attrname, pattern) for pattern in self.testNamePatterns)
testFnNames = list(filter(shouldIncludeMethod, dir(testCaseClass)))
if self.sortTestMethodsUsing:
testFnNames.sort(key=functools.cmp_to_key(self.sortTestMethodsUsing))
return testFnNames
if __name__ == '__main__':
import argparse
import os
import unittest
import sys
import system_tests
parser = argparse.ArgumentParser(description="The system test suite")
parser.add_argument(
"--config_file",
type=str,
@ -29,7 +52,6 @@ if __name__ == '__main__':
help="enable debugging output",
action='store_true'
)
parser.add_argument(
"dir_or_file",
help="root directory under which the testsuite searches for tests or a"
@ -43,16 +65,18 @@ if __name__ == '__main__':
args = parser.parse_args()
conf_file = args.config_file[0]
DEFAULT_ROOT = os.path.abspath(os.path.dirname(conf_file))
system_tests.set_debug_mode(args.debug)
system_tests.configure_suite(conf_file)
testLoader = MyTestLoader()
testLoader.testMethodPrefix = ''
testLoader.testNamePatterns = ['test*', '*test']
if args.dir_or_file is None or os.path.isdir(args.dir_or_file):
discovered_tests = unittest.defaultTestLoader.discover(
discovered_tests = testLoader.discover(
args.dir_or_file or DEFAULT_ROOT
)
elif os.path.isfile(args.dir_or_file):
discovered_tests = unittest.defaultTestLoader.discover(
discovered_tests = testLoader.discover(
os.path.dirname(args.dir_or_file),
pattern=os.path.split(args.dir_or_file)[1],
)
@ -62,7 +86,7 @@ if __name__ == '__main__':
.format(DEFAULT_ROOT),
file=sys.stderr
)
discovered_tests = unittest.defaultTestLoader.discover(
discovered_tests = testLoader.discover(
DEFAULT_ROOT
)