summaryrefslogtreecommitdiff
path: root/morphlib/sourcepool_tests.py
blob: f3740049901953a68505cd79b2c5b2fc7270505d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# Copyright (C) 2012-2014  Codethink Limited
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.


import unittest

import morphlib


class DummySource(object):

    def __init__(self):
        self.name = 'dummy'
        self.repo_name = 'repo'
        self.original_ref = 'original/ref'
        self.sha1 = 'dummy.sha1'
        self.filename = 'dummy.morph'
        self.morphology = {}
        self.dependencies = []
        self.dependents = []


class SourcePoolTests(unittest.TestCase):

    def setUp(self):
        self.pool = morphlib.sourcepool.SourcePool()
        self.source = DummySource()

    def test_is_empty_initially(self):
        self.assertEqual(list(self.pool), [])
        self.assertEqual(len(self.pool), 0)

    def test_adds_source(self):
        self.pool.add(self.source)
        self.assertEqual(list(self.pool), [self.source])

    def test_looks_up_source(self):
        self.pool.add(self.source)
        result = self.pool.lookup(self.source.repo_name,
                                  self.source.original_ref,
                                  self.source.filename)
        self.assertEqual(result, [self.source])

    def test_iterates_in_add_order(self):
        sources = []
        for i in range(10):
            source = DummySource()
            source.filename = str(i)
            self.pool.add(source)
            sources.append(source)
        self.assertEqual(list(self.pool), sources)