diff options
author | Lars Wirzenius <lars.wirzenius@codethink.co.uk> | 2012-04-10 16:12:06 +0100 |
---|---|---|
committer | Lars Wirzenius <lars.wirzenius@codethink.co.uk> | 2012-04-10 16:28:13 +0100 |
commit | caaa37d42dec002ffe20f2152767f3ce37cb1bf5 (patch) | |
tree | 9bfb0e630f0688aeb31940212da5c32e738cf74f /morphlib/sourcepool_tests.py | |
parent | 7ec6cd23cefe5e116a54c6c0cb2aa0669adcd991 (diff) | |
download | morph-caaa37d42dec002ffe20f2152767f3ce37cb1bf5.tar.gz |
Add SourcePool class and make Source store its morphology filename
Diffstat (limited to 'morphlib/sourcepool_tests.py')
-rw-r--r-- | morphlib/sourcepool_tests.py | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/morphlib/sourcepool_tests.py b/morphlib/sourcepool_tests.py new file mode 100644 index 00000000..35a94b39 --- /dev/null +++ b/morphlib/sourcepool_tests.py @@ -0,0 +1,65 @@ +# Copyright (C) 2012 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.repo = 'dummy.repo' + 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, self.source.sha1, + self.source.filename) + self.assertEqual(result, self.source) + + def test_lookup_raises_keyerror_if_not_found(self): + self.assertRaises(KeyError, self.pool.lookup, self.source.repo, + self.source.sha1, self.source.filename) + + 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) + |