86
by Olivier Tilloy
Added some unit tests for basic functionalities. These tests will help spot regressions in the future. |
1 |
# -*- coding: utf-8 -*-
|
2 |
||
3 |
# ******************************************************************************
|
|
4 |
#
|
|
363
by Olivier Tilloy
Updated header. |
5 |
# Copyright (C) 2008-2011 Olivier Tilloy <olivier@tilloy.net>
|
86
by Olivier Tilloy
Added some unit tests for basic functionalities. These tests will help spot regressions in the future. |
6 |
#
|
7 |
# This file is part of the pyexiv2 distribution.
|
|
8 |
#
|
|
9 |
# pyexiv2 is free software; you can redistribute it and/or
|
|
10 |
# modify it under the terms of the GNU General Public License
|
|
11 |
# as published by the Free Software Foundation; either version 2
|
|
12 |
# of the License, or (at your option) any later version.
|
|
13 |
#
|
|
14 |
# pyexiv2 is distributed in the hope that it will be useful,
|
|
15 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
16 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
17 |
# GNU General Public License for more details.
|
|
18 |
#
|
|
19 |
# You should have received a copy of the GNU General Public License
|
|
20 |
# along with pyexiv2; if not, write to the Free Software
|
|
21 |
# Foundation, Inc., 51 Franklin Street, 5th Floor, Boston, MA 02110-1301 USA.
|
|
22 |
#
|
|
363
by Olivier Tilloy
Updated header. |
23 |
# Author: Olivier Tilloy <olivier@tilloy.net>
|
86
by Olivier Tilloy
Added some unit tests for basic functionalities. These tests will help spot regressions in the future. |
24 |
#
|
25 |
# ******************************************************************************
|
|
26 |
||
301.1.1
by Olivier Tilloy
Allow running the unit tests from anywhere. |
27 |
import os.path |
86
by Olivier Tilloy
Added some unit tests for basic functionalities. These tests will help spot regressions in the future. |
28 |
import hashlib |
29 |
||
301.1.1
by Olivier Tilloy
Allow running the unit tests from anywhere. |
30 |
|
343
by Olivier Tilloy
Moved EMPTY_JPG_DATA to the testutils module. |
31 |
EMPTY_JPG_DATA = \ |
32 |
'\xff\xd8\xff\xe0\x00\x10JFIF\x00\x01\x01\x01\x00H\x00H\x00\x00\xff\xdb' \ |
|
33 |
'\x00C\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff' \ |
|
34 |
'\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff' \ |
|
35 |
'\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff' \ |
|
36 |
'\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xc0\x00\x0b\x08' \ |
|
37 |
'\x00\x01\x00\x01\x01\x01\x11\x00\xff\xc4\x00\x1f\x00\x00\x01\x05\x01\x01' \ |
|
38 |
'\x01\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x01\x02\x03\x04\x05\x06' \ |
|
39 |
'\x07\x08\t\n\x0b\xff\xc4\x00\xb5\x10\x00\x02\x01\x03\x03\x02\x04\x03\x05' \ |
|
40 |
'\x05\x04\x04\x00\x00\x01}\x01\x02\x03\x00\x04\x11\x05\x12!1A\x06\x13Qa' \ |
|
41 |
'\x07"q\x142\x81\x91\xa1\x08#B\xb1\xc1\x15R\xd1\xf0$3br\x82\t\n\x16\x17' \ |
|
42 |
"\x18\x19\x1a%&\'()*456789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz\x83\x84\x85" \ |
|
43 |
'\x86\x87\x88\x89\x8a\x92\x93\x94\x95\x96\x97\x98\x99\x9a\xa2\xa3\xa4\xa5' \ |
|
44 |
'\xa6\xa7\xa8\xa9\xaa\xb2\xb3\xb4\xb5\xb6\xb7\xb8\xb9\xba\xc2\xc3\xc4\xc5' \ |
|
45 |
'\xc6\xc7\xc8\xc9\xca\xd2\xd3\xd4\xd5\xd6\xd7\xd8\xd9\xda\xe1\xe2\xe3\xe4' \ |
|
46 |
'\xe5\xe6\xe7\xe8\xe9\xea\xf1\xf2\xf3\xf4\xf5\xf6\xf7\xf8\xf9\xfa\xff\xda' \ |
|
47 |
'\x00\x08\x01\x01\x00\x00?\x00\x92\xbf\xff\xd9' |
|
48 |
||
49 |
||
301.1.1
by Olivier Tilloy
Allow running the unit tests from anywhere. |
50 |
def get_absolute_file_path(filepath): |
51 |
"""
|
|
52 |
Return the absolute file path for the file path given in argument,
|
|
53 |
considering it is relative to the caller script's directory.
|
|
54 |
"""
|
|
55 |
return os.path.join(os.path.dirname(os.path.abspath(__file__)), filepath) |
|
56 |
||
57 |
||
86
by Olivier Tilloy
Added some unit tests for basic functionalities. These tests will help spot regressions in the future. |
58 |
def CheckFileSum(filename, md5sum): |
59 |
"""
|
|
60 |
Test the MD5 sum of a given file against the expected value.
|
|
61 |
||
62 |
Keyword arguments:
|
|
63 |
filename -- the name of the file to test
|
|
64 |
md5sum -- the expected value of the MD5 sum of the file
|
|
65 |
"""
|
|
279
by Olivier Tilloy
Fix unit tests on windows. |
66 |
f = open(filename, 'rb') |
86
by Olivier Tilloy
Added some unit tests for basic functionalities. These tests will help spot regressions in the future. |
67 |
return (hashlib.md5(f.read()).hexdigest() == md5sum) |
68 |