~ara/ubuntu/lucid/mago/fix_tests_lucid

« back to all changes in this revision

Viewing changes to mago/check.py

  • Committer: Bazaar Package Importer
  • Author(s): Ara Pulido
  • Date: 2009-08-04 09:21:40 UTC
  • Revision ID: james.westby@ubuntu.com-20090804092140-7ggrh3nlujflk0v8
Tags: upstream-0.1
ImportĀ upstreamĀ versionĀ 0.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
"""
 
2
This is the check.py module.
 
3
 
 
4
The check module provides different ways to check if the test failed or passed
 
5
"""
 
6
import filecmp
 
7
import os
 
8
import sys
 
9
import shutil
 
10
from ldtputils import imagecompare
 
11
 
 
12
FAIL = "fail"
 
13
PASS = "pass"
 
14
 
 
15
class Check:
 
16
    """
 
17
    Superclass for the rest of the test checks
 
18
    """
 
19
    def __init__(self):
 
20
        return
 
21
 
 
22
class FileComparison(Check):
 
23
    """
 
24
    Test check for file comparison. If two files are equal, the test passes.
 
25
    """
 
26
    def __init__(self, oracle, test):
 
27
        """
 
28
        Main constructor. It requires two existing files paths.
 
29
 
 
30
        @type oracle: string
 
31
        @param oracle: The path to the oracle file to compare the test file against.
 
32
 
 
33
        @type test: string
 
34
        @param test: The path to the test file to compare the test file against.
 
35
        """
 
36
 
 
37
        Check.__init__(self)
 
38
 
 
39
        self.oracle = oracle
 
40
        self.test   = test
 
41
 
 
42
    def perform_test(self):
 
43
        """
 
44
        Perform the test check. 
 
45
 
 
46
        It the two files are equal, the test passes. Otherwise, it fails.
 
47
        """
 
48
        if filecmp.cmp(self.oracle, self.test):
 
49
            return PASS
 
50
        else:
 
51
            return FAIL
 
52
 
 
53
class ScreenshotCompare(FileComparison):
 
54
    def perform_test(self, max_diff=0.0):
 
55
        res = imagecompare(self.oracle, self.test)
 
56
        if res > max_diff:
 
57
            return FAIL
 
58
        else:
 
59
            return PASS
 
60
 
 
61
    def calibrate(self):
 
62
        shutil.copy(self.test, self.oracle)