# # # rename "grapher" # to "experiments/grapher" # # rename "tests" # to "experiments/tests" # # add_dir "experiments" # # add_file "experiments/README" # content [4fead89086ec35aac4a08701363c9540a88f317b] # # add_file "tests.py" # content [4dd3dd2828cad46f83d81ae47a7fb3b22db8302c] # # patch "ChangeLog" # from [ffae33a4ed59b6f6fe964e79afedd57c6040a7e3] # to [97bda855566c0af9365a6375072eff9908e5f12a] # # patch "config.py.example" # from [49e135fe5ecb78922ba027f1e68d7b55f040e37d] # to [9248282147264a3a9d09df9de7337b672e2d41f2] # # set "tests.py" # attr "mtn:execute" # value "true" # ============================================================ --- experiments/README 4fead89086ec35aac4a08701363c9540a88f317b +++ experiments/README 4fead89086ec35aac4a08701363c9540a88f317b @@ -0,0 +1,5 @@ + +Things in here are old ideas, or new ones, that aren't ready +for prime time yet. They might even be embarassingly bad prototypes +written when half asleep. Hence, beware! + ============================================================ --- tests.py 4dd3dd2828cad46f83d81ae47a7fb3b22db8302c +++ tests.py 4dd3dd2828cad46f83d81ae47a7fb3b22db8302c @@ -0,0 +1,92 @@ +#!/usr/bin/env python2.4 + +# Copyright (C) 2005 Grahame Bowland +# +# This program is made available under the GNU GPL version 2.0 or +# greater. See the accompanying file COPYING for details. +# +# This program is distributed WITHOUT ANY WARRANTY; without even the +# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR +# PURPOSE. + +# +# Unit tests for ViewMTN +# +# Aiming for reasonably full coverage, but the tests are being +# written after the application so it's slow and tedious work :-) +# + +import unittest +import stat +import os + +# modules we're testing.. +import viewmtn +import mtn + +class ConfigTest(unittest.TestCase): + "Test that the configuration file is correct" + + def can_access(self, fname): + self.failIf (not os.access(fname, os.R_OK), "Cannot access file: " + fname) + + def is_uri(self, uri): + self.failIf (not isinstance(uri, str), "URIs must be instances of ") + self.failIf (not uri[-1] == '/', "All URIs in config file must end in '/'") + + def is_file(self, fname): + self.failIf (not stat.S_ISREG(os.stat(fname).st_mode), "Files in config file must be regular files: " + fname) + + def is_command(self, fname): + self.failIf (not os.access(fname, os.X_OK), "Must be able to execute: " + fname) + + def is_directory(self, fname): + self.failIf (not stat.S_ISDIR(os.stat(fname).st_mode), "Must be a directory: " + fname) + + check_keys = [(lambda self : self.config, + lambda obj, key : hasattr(obj, key), + lambda obj, key : getattr(obj, key), + { 'dynamic_uri_path' : (is_uri,), + 'static_uri_path' : (is_uri,), + 'running_under_apache2' : None, + 'monotone' : (can_access, is_file, is_command), + 'dbfile' : (can_access, is_file,), + 'highlight_command' : (can_access, is_file, is_command), + 'graphopts' : None, + 'icon_theme' : None, + 'icon_size' : None, + }), + (lambda self: self.config.graphopts, + lambda obj, key : obj.has_key(key), + lambda obj, key : obj[key], + { 'directory' : (can_access, is_directory), + 'uri' : (is_uri,), + 'dot' : (can_access, is_file, is_command), + 'nodeopts' : None }), + (lambda self: self.config.graphopts['nodeopts'], + lambda obj, key : obj.has_key(key), + lambda obj, key : obj[key], + { 'fontname' : None, + 'fontsize' : None, + 'shape' : None, + 'height' : None, + 'spline' : None, + 'style' : None, + 'fillcolor' : None }) ] + + def setUp(self): + self.config = __import__('config') + + def testRequiredKeys(self): + "all required configuration options present" + for val_func, has_func, get_func, keys in self.check_keys: + to_check = val_func(self) + for key in keys: + self.failIf(not has_func(to_check, key), "Required configuration option '%s' not found." % key) + funcs = keys[key] + if funcs == None: continue + val = get_func(to_check, key) + map(lambda func : func(self, val), funcs) + +if __name__ == '__main__': + unittest.main() ============================================================ --- ChangeLog ffae33a4ed59b6f6fe964e79afedd57c6040a7e3 +++ ChangeLog 97bda855566c0af9365a6375072eff9908e5f12a @@ -1,3 +1,13 @@ +2007-04-02 Grahame Bowland + + * start of a test suite using PyUnit; first off, + check that config.py is sane. This is actually + useful for people that accidentally specify wrong + things in here. + * move some experimental / old things into + experimental/ so that people know they're not + something you should actually try running. + 2007-04-01 Grahame Bowland * fix a number of places where dynamic_join() ============================================================ --- config.py.example 49e135fe5ecb78922ba027f1e68d7b55f040e37d +++ config.py.example 9248282147264a3a9d09df9de7337b672e2d41f2 @@ -78,10 +78,4 @@ icon_size = '16' icon_theme = 'gnome' icon_size = '16' -# for tests/ -# don't worry about these unless you are going to run -# the tests -test_branch = "net.angrygoats.viewmtn" -#test_revision = "53b7a6866f0f7268a8eb721e8d74688de8567fb8" -test_revision = "ea14ea3aadb3a02ffe5041e0a98db15306cbcd81"