-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathtest_uvtt2fgu.py
executable file
·82 lines (71 loc) · 3.47 KB
/
test_uvtt2fgu.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/usr/bin/env python3
import argparse
from pathlib import Path
import unittest
import uvtt2fgu
class TestComposeFilePaths(unittest.TestCase):
def setUp(self) -> None:
uvtt2fgu.loadConfigData(None)
uvtt2fgu.__dict__['configData'].xmlpath = '.'
uvtt2fgu.configData.pngpath = '.'
uvtt2fgu.configData.jpgpath = '.'
return super().setUp()
def test_fileonly(self) -> None:
'''Test with a filename, and no output directory specified'''
(uvttpath, pngpath, jpgpath, xmlpath) = uvtt2fgu.composeFilePaths(
Path('filename.dd2vtt'))
self.assertEqual(uvttpath, Path('filename.dd2vtt'))
self.assertEqual(pngpath, Path('filename.png'))
self.assertEqual(jpgpath, Path('filename.jpg'))
self.assertEqual(xmlpath, Path('filename.xml'))
def test_filewithpath(self) -> None:
'''Test with a filename with a relative path, and no output directory specified'''
(uvttpath, pngpath, jpgpath, xmlpath) = uvtt2fgu.composeFilePaths(
Path('abc/filename.dd2vtt'))
self.assertEqual(uvttpath, Path('abc/filename.dd2vtt'))
self.assertEqual(pngpath, Path('filename.png'))
self.assertEqual(jpgpath, Path('filename.jpg'))
self.assertEqual(xmlpath, Path('filename.xml'))
def test_filewithoutputpath(self) -> None:
'''Test with a filename, and an output directory specified'''
uvtt2fgu.configData.xmlpath = 'd1x'
uvtt2fgu.configData.jpgpath = 'd2x'
uvtt2fgu.configData.pngpath = 'd3x'
(uvttpath, pngpath, jpgpath, xmlpath) = uvtt2fgu.composeFilePaths(
Path('filename.dd2vtt'))
self.assertEqual(uvttpath, Path('filename.dd2vtt'))
self.assertEqual(pngpath, Path('d3x/filename.png'))
self.assertEqual(jpgpath, Path('d2x/filename.jpg'))
self.assertEqual(xmlpath, Path('d1x/filename.xml'))
def test_filewithpathwithoutputpath(self) -> None:
'''Test with a filename with a relative path, and an output directory specified'''
uvtt2fgu.configData.xmlpath = 'd1x'
uvtt2fgu.configData.jpgpath = 'd2x'
uvtt2fgu.configData.pngpath = 'd3x'
(uvttpath, pngpath, jpgpath, xmlpath) = uvtt2fgu.composeFilePaths(
Path('abc/filename.dd2vtt'))
self.assertEqual(uvttpath, Path('abc/filename.dd2vtt'))
self.assertEqual(pngpath, Path('d3x/filename.png'))
self.assertEqual(jpgpath, Path('d2x/filename.jpg'))
self.assertEqual(xmlpath, Path('d1x/filename.xml'))
class TestPortalAdjust(unittest.TestCase):
def test_percent(self) -> None:
'''Test the custom argument parser'''
parser = argparse.ArgumentParser()
parser.add_argument('--foo', nargs=1, action=uvtt2fgu.PortalAdjust)
args = parser.parse_args('--foo 25%'.split())
self.assertEqual(args.foo, '25%')
def test_pixels(self) -> None:
'''Test the custom argument parser'''
parser = argparse.ArgumentParser()
parser.add_argument('--foo', nargs=1, action=uvtt2fgu.PortalAdjust)
args = parser.parse_args('--foo 99px'.split())
self.assertEqual(args.foo, '99px')
def test_other(self) -> None:
'''Test the custom argument parser'''
parser = argparse.ArgumentParser()
parser.add_argument('--foo', nargs=1, action=uvtt2fgu.PortalAdjust)
with self.assertRaises(argparse.ArgumentTypeError):
args = parser.parse_args('--foo 99'.split())
if __name__ == '__main__':
unittest.main()