~gary/charms/oneiric/buildbot-master/typo

« back to all changes in this revision

Viewing changes to hooks/tests.py

  • Committer: Brad Crittenden
  • Date: 2012-02-02 19:38:58 UTC
  • mto: (10.1.1 generate-slave-names)
  • mto: This revision was merged to the branch mainline in revision 11.
  • Revision ID: bac@canonical.com-20120202193858-8urkwwnrh8hupfz2
Working python hooks.  Added config file for lpbuildbot.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
from subprocess import CalledProcessError
 
2
import tempfile
1
3
import unittest
2
 
from subprocess import CalledProcessError
3
 
from helpers import command
 
4
 
 
5
from helpers import (
 
6
    command,
 
7
    DictDiffer,
 
8
    load_pickle,
 
9
    save_pickle,
 
10
    )
4
11
 
5
12
 
6
13
class testCommand(unittest.TestCase):
52
59
        ls(*'tests.py install'.split())
53
60
 
54
61
 
 
62
class testDictDiffer(unittest.TestCase):
 
63
 
 
64
    def testStr(self):
 
65
        a = dict(cow='moo', pig='oink')
 
66
        b = dict(cow='moo', pig='oinkoink', horse='nay')
 
67
        diff = DictDiffer(b, a)
 
68
        s = str(diff)
 
69
        self.assertIn("added: {'horse': None} -> {'horse': 'nay'}", s)
 
70
        self.assertIn("removed: {} -> {}", s)
 
71
        self.assertIn("changed: {'pig': 'oink'} -> {'pig': 'oinkoink'}", s)
 
72
        self.assertIn("unchanged: ['cow']", s)
 
73
 
 
74
    def testStrUnmodified(self):
 
75
        a = dict(cow='moo', pig='oink')
 
76
        diff = DictDiffer(a, a)
 
77
        s = str(diff)
 
78
        self.assertEquals('no changes', s)
 
79
 
 
80
    def testAddedOrChanged(self):
 
81
        a = dict(cow='moo', pig='oink')
 
82
        b = dict(cow='moo', pig='oinkoink', horse='nay')
 
83
        diff = DictDiffer(b, a)
 
84
        expected = set(['horse', 'pig'])
 
85
        self.assertEquals(expected, diff.added_or_changed)
 
86
class testPicklers(unittest.TestCase):
 
87
 
 
88
    def testSaveAndLoad(self):
 
89
        fd = tempfile.NamedTemporaryFile()
 
90
        fn = fd.name
 
91
        fd.close()
 
92
        orig = dict(a=1, b=2)
 
93
        save_pickle(orig, fn)
 
94
        retrieved = load_pickle(fn)
 
95
        self.assertEquals(orig, retrieved)
 
96
 
 
97
 
55
98
if __name__ == '__main__':
56
99
    unittest.main()