~ubuntu-branches/ubuntu/saucy/mago/saucy

« back to all changes in this revision

Viewing changes to mago/cmd/result.py

  • Committer: Bazaar Package Importer
  • Author(s): Michael Vogt
  • Date: 2011-02-08 13:32:13 UTC
  • mfrom: (1.1.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20110208133213-m1og7ey0m990chg6
Tags: 0.3+bzr20-0ubuntu1
* debian/rules:
  - updated to debhelper 7
  - use dh_python2 instead of python-central
* debian/pycompat:
  - removed, no longer needed
* debian/control:
  - dropped cdbs and python-central dependencies
* bzr snapshot of the current trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
"""
2
 
This module provides a class to easily store test results
3
 
"""
4
 
from time import strftime
5
 
from shutil import move
6
 
import ldtputils
7
 
 
8
 
from . import globals
9
 
from .utils import safe_make_directory
10
 
 
11
 
class ResultDict(dict):
12
 
    """
13
 
    Dictionary-like class to store test case results
14
 
    """
15
 
    def __setitem__(self, key, value):
16
 
        """
17
 
        Set value as a one element list using key
18
 
        """
19
 
        dict.__setitem__(self, key, [value])
20
 
 
21
 
 
22
 
    def append(self, key, value):
23
 
        """
24
 
        Append a result using key
25
 
        """
26
 
        values = self.get(key, None)
27
 
        if not values:
28
 
            self[key] = value
29
 
        else:
30
 
            values.append(value)
31
 
 
32
 
 
33
 
    def append_screenshot(self, screenshot_file=None):
34
 
        """
35
 
        Take screenshot and append the filename to screenshot results
36
 
        """
37
 
        _logFile = "%s/screenshot-%s.png" % (globals.SCREENSHOTS_SHARE,
38
 
                                             strftime ("%m-%d-%Y-%H-%M-%s"))
39
 
        safe_make_directory(globals.SCREENSHOTS_SHARE)
40
 
        if not screenshot_file:
41
 
            ldtputils.imagecapture(out_file = _logFile)
42
 
        else:
43
 
            move(screenshot_file, _logFile)
44
 
        self.append('screenshot', _logFile)