~ubuntu-branches/ubuntu/precise/landscape-client/precise

« back to all changes in this revision

Viewing changes to landscape/tests/helpers.py

  • Committer: Package Import Robot
  • Author(s): Andreas Hasenack
  • Date: 2012-03-19 09:33:34 UTC
  • mto: This revision was merged to the branch mainline in revision 41.
  • Revision ID: package-import@ubuntu.com-20120319093334-oxjttz163vvfgq8s
Tags: upstream-12.04
ImportĀ upstreamĀ versionĀ 12.04

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
from cStringIO import StringIO
 
2
from ConfigParser import ConfigParser
2
3
import logging
3
4
import shutil
4
5
import pprint
7
8
import sys
8
9
import unittest
9
10
 
 
11
 
10
12
from logging import Handler, ERROR, Formatter
11
13
from twisted.trial.unittest import TestCase
12
14
from twisted.internet.defer import Deferred
74
76
                                           pprint.pformat(obtained)))
75
77
 
76
78
    def assertMessages(self, obtained, expected):
77
 
        self.assertEquals(type(obtained), list)
78
 
        self.assertEquals(type(expected), list)
 
79
        self.assertEqual(type(obtained), list)
 
80
        self.assertEqual(type(expected), list)
79
81
        for obtained_message, expected_message in zip(obtained, expected):
80
82
            self.assertMessage(obtained_message, expected_message)
81
83
        obtained_len = len(obtained)
121
123
        Assert that the given C{deferred} results in the given C{result}.
122
124
        """
123
125
        self.assertTrue(isinstance(deferred, Deferred))
124
 
        return deferred.addCallback(self.assertEquals, result)
 
126
        return deferred.addCallback(self.assertEqual, result)
125
127
 
126
128
    def assertFileContent(self, filename, expected_content):
127
129
        fd = open(filename)
128
130
        actual_content = fd.read()
129
131
        fd.close()
130
 
        self.assertEquals(expected_content, actual_content)
 
132
        self.assertEqual(expected_content, actual_content)
 
133
 
 
134
    def assertConfigEqual(self, first, second):
 
135
        """
 
136
        Compare two configuration files for equality.  The order of parameters
 
137
        and comments may be different but the actual parameters and sections
 
138
        must be the same.
 
139
        """
 
140
        first_fp = StringIO(first)
 
141
        first_parser = ConfigParser()
 
142
        first_parser.readfp(first_fp)
 
143
 
 
144
        second_fp = StringIO(second)
 
145
        second_parser = ConfigParser()
 
146
        second_parser.readfp(second_fp)
 
147
 
 
148
        self.assertEqual(set(first_parser.sections()),
 
149
                         set(second_parser.sections()))
 
150
        for section in first_parser.sections():
 
151
            self.assertEqual(dict(first_parser.items(section)),
 
152
                             dict(second_parser.items(section)))
131
153
 
132
154
    def makePersistFile(self, *args, **kwargs):
133
155
        """Return a temporary filename to be used by a L{Persist} object.
474
496
 
475
497
 
476
498
class ProcessDataBuilder(object):
477
 
    """Builder creates sample data for the process info plugin to consume."""
 
499
    """Builder creates sample data for the process info plugin to consume.
 
500
 
 
501
    @param sample_dir: The directory for sample data.
 
502
    """
478
503
 
479
504
    RUNNING = "R (running)"
480
505
    STOPPED = "T (stopped)"
485
510
    ZOMBIE = "Z (zombie)"
486
511
 
487
512
    def __init__(self, sample_dir):
488
 
        """Initialize factory with directory for sample data."""
489
513
        self._sample_dir = sample_dir
490
514
 
491
515
    def create_data(self, process_id, state, uid, gid,
610
634
        if self._shared and self not in self.__class__._instances:
611
635
            self.__class__._instances.add(self)
612
636
        result.startTest(self)
613
 
        if self.getSkip(): # don't run test methods that are marked as .skip
 
637
        if self.getSkip():  # don't run test methods that are marked as .skip
614
638
            result.addSkip(self, self.getSkip())
615
639
            result.stopTest(self)
616
640
            return
641
665
 
642
666
### Copied from Twisted, to fix a bug in trial in Twisted 2.2! ###
643
667
 
 
668
 
644
669
class UnsupportedTrialFeature(Exception):
645
670
    """A feature of twisted.trial was used that pyunit cannot support."""
646
671
 
651
676
    supports the extended result types from Trial, and also supports
652
677
    L{twisted.python.failure.Failure}s being passed to L{addError} and
653
678
    L{addFailure}.
 
679
 
 
680
    @param original: A C{TestResult} instance from C{unittest}.
654
681
    """
655
682
 
656
683
    def __init__(self, original):
657
 
        """
658
 
        @param original: A C{TestResult} instance from C{unittest}.
659
 
        """
660
684
        self.original = original
661
685
 
662
686
    def _exc_info(self, err):