2 # Copyright (C) Jelmer Vernooij <jelmer@samba.org> 2010
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 3 of the License, or
7 # (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 from buildfarm import setup_db
20 from storm import database
21 from storm.store import Store
22 from testtools import TestCase
27 class BuildFarmTestCase(TestCase):
28 """Test case class that provides a build farm data directory and convenience methods.
31 def create_mock_logfile(self, tree, host, compiler, rev=None,
32 kind="stdout", contents="FOO"):
33 basename = "build.%s.%s.%s" % (tree, host, compiler)
35 basename += "-%s" % rev
36 path = os.path.join(self.path, "data", "oldrevs", basename)
38 path = os.path.join(self.path, "data", "upload", basename)
41 elif kind == "stderr":
44 raise ValueError("Unknown log kind %r" % kind)
52 def write_compilers(self, compilers):
53 f = open(os.path.join(self.path, "web", "compilers.list"), "w")
55 for compiler in compilers:
56 f.write("%s\n" % compiler)
60 def write_trees(self, trees):
61 f = open(os.path.join(self.path, "web", "trees.conf"), "w")
65 for k, v in trees[t].iteritems():
66 f.write("%s = %s\n" % (k, v))
72 super(BuildFarmTestCase, self).setUp()
73 self.path = tempfile.mkdtemp()
75 for subdir in ["data", "data/upload", "data/oldrevs", "cache", "web", "lcov", "lcov/data"]:
76 os.mkdir(os.path.join(self.path, subdir))
78 db = database.create_database("sqlite:"+os.path.join(self.path, "hostdb.sqlite"))
83 shutil.rmtree(self.path)
84 super(BuildFarmTestCase, self).tearDown()