~osomon/pyexiv2/pyexiv2-0.3

« back to all changes in this revision

Viewing changes to unittest/testutils.py

  • Committer: Olivier Tilloy
  • Date: 2008-01-30 21:36:43 UTC
  • Revision ID: olivier@tilloy.net-20080130213643-skrpcsnpjsivu50h
Added some unit tests for basic functionalities. These tests will help spot regressions in the future.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/python
 
2
# -*- coding: utf-8 -*-
 
3
 
 
4
# ******************************************************************************
 
5
#
 
6
# Copyright (C) 2006-2007 Olivier Tilloy <olivier@tilloy.net>
 
7
#
 
8
# This file is part of the pyexiv2 distribution.
 
9
#
 
10
# pyexiv2 is free software; you can redistribute it and/or
 
11
# modify it under the terms of the GNU General Public License
 
12
# as published by the Free Software Foundation; either version 2
 
13
# of the License, or (at your option) any later version.
 
14
#
 
15
# pyexiv2 is distributed in the hope that it will be useful,
 
16
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
17
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
18
# GNU General Public License for more details.
 
19
#
 
20
# You should have received a copy of the GNU General Public License
 
21
# along with pyexiv2; if not, write to the Free Software
 
22
# Foundation, Inc., 51 Franklin Street, 5th Floor, Boston, MA 02110-1301 USA.
 
23
#
 
24
#
 
25
# File:      testutils.py
 
26
# Author(s): Olivier Tilloy <olivier@tilloy.net>
 
27
#
 
28
# ******************************************************************************
 
29
 
 
30
import hashlib
 
31
 
 
32
def CheckFileSum(filename, md5sum):
 
33
    """
 
34
    Test the MD5 sum of a given file against the expected value.
 
35
 
 
36
    Keyword arguments:
 
37
    filename -- the name of the file to test
 
38
    md5sum -- the expected value of the MD5 sum of the file
 
39
    """
 
40
    f = open(filename)
 
41
    return (hashlib.md5(f.read()).hexdigest() == md5sum)
 
42