gump-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From leosim...@apache.org
Subject svn commit: r156255 - in gump/branches/Gump3/pygump/python/gump: model/__init__.py test/testModel.py
Date Sat, 05 Mar 2005 15:15:03 GMT
Author: leosimons
Date: Sat Mar  5 07:15:02 2005
New Revision: 156255

URL: http://svn.apache.org/viewcvs?view=rev&rev=156255
Log:
Approximately complete coverage for the model. Phew...

Modified:
    gump/branches/Gump3/pygump/python/gump/model/__init__.py
    gump/branches/Gump3/pygump/python/gump/test/testModel.py

Modified: gump/branches/Gump3/pygump/python/gump/model/__init__.py
URL: http://svn.apache.org/viewcvs/gump/branches/Gump3/pygump/python/gump/model/__init__.py?view=diff&r1=156254&r2=156255
==============================================================================
--- gump/branches/Gump3/pygump/python/gump/model/__init__.py (original)
+++ gump/branches/Gump3/pygump/python/gump/model/__init__.py Sat Mar  5 07:15:02 2005
@@ -237,7 +237,7 @@
                  url = None,
                  description = None):
         Module.__init__(self, repository, name, url, description)
-        self.directory = directory
+        self.path = path
 
 #TODO: class PerforceModule
 
@@ -261,6 +261,9 @@
                           build of this project results in
     """
     def __init__(self, module, name):
+        assert isinstance(module, Module)
+        assert isinstance(name, str)
+        
         self.module = module
         self.name   = name
         
@@ -269,20 +272,35 @@
         self.commands=[]
         self.outputs=[]
     
-    def add_dependency(self, dependency):
-        self.module.repository.workspace.dependencies.append(dependency)
-        self.dependencies.append(dependency)
-        if type(dependency.dependency) == type(self): # might be a string for a bad
-                                                      # dependency
-            dependency.dependency.add_dependee(dependency)
-    
-    def add_dependee(self, dependee):
-        self.dependees.append(dependee)
+    def add_dependency(self, relationship):
+        assert isinstance(relationship, Dependency)
+        # This can make your head hurt :-D
+        # let's say that self is "Project A", and 'dependency' is "Project B"
+        # Calling this method means that Project A depends on Project B, so
+        # Project B is a dependency of Project A
+        # Project A is a dependee of Project B
+        self.module.repository.workspace.dependencies.append(relationship)
+        self.dependencies.append(relationship)
+        #print "%s is told %s depends on %s" % (self.name, self.name, relationship.dependency.name)
+        
+        # register Project A as a dependee of Project B
+        # relationship.dependency is Project B
+        # relationship.dependency.add_dependee() registers A with B
+        #print "%s is telling %s that %s depends on %s" % (self.name, relationship.dependency.name,
self.name, relationship.dependency.name)
+        if isinstance(relationship.dependency, Project): # might be a string for a bad
+                                                            # dependency
+            relationship.dependency.add_dependee(relationship)
+    
+    def add_dependee(self, relationship):
+        #print "%s is told that %s is a dependee of %s" % (self.name, relationship.dependee.name,
self.name)
+        self.dependees.append(relationship)
     
     def add_command(self, command):
+        assert isinstance(command, Command)
         self.commands.append(command)
     
     def add_output(self, output):
+        assert isinstance(output, Output)
         self.outputs.append(output)
 
 DEPENDENCY_INHERIT_NONE          = "none"
@@ -313,6 +331,10 @@
                         used if this dependency cannot be satisfied
         - runtime    -- flag indicating whether the dependee needs this
                         dependency at runtime or just for building
+        - inherit    -- option dictating whether this dependency should
+                        "cascade" or "propagate in some form
+        - specific_output_id -- option that specifies one output ID from
+                        the specified project that is depended on
     """
     def __init__(self,
                  dependency,
@@ -321,6 +343,8 @@
                  runtime  = False,
                  inherit  = DEPENDENCY_INHERIT_NONE,
                  specific_output_id = None):
+        assert isinstance(dependency, Project)
+        assert isinstance(dependee, Project)
         self.dependency         = dependency
         self.dependee           = dependee
         self.optional           = optional
@@ -338,6 +362,7 @@
         - project -- the containing project
     """
     def __init__(self, project):
+        assert isinstance(project, Project)
         self.project = project
     pass
 
@@ -353,6 +378,7 @@
         - directory -- the directory to create
     """
     def __init__(self, project, directory):
+        assert isinstance(directory, str)
         Command.__init__(self, project)
         self.directory = directory
 
@@ -368,6 +394,7 @@
         - directory -- the directory to delete
     """
     def __init__(self, project, directory):
+        assert isinstance(directory,str)
         Command.__init__(self, project)
         self.directory = directory
 
@@ -383,6 +410,10 @@
                   tuple
     """
     def __init__(self, project, name, args=[]):
+        assert isinstance(name, str)
+        assert isinstance(args, list)
+        for arg in args:
+            assert isinstance(arg, str)
         Command.__init__(self, project)
         self.name = name
         self.args = args
@@ -403,6 +434,7 @@
         - id      -- a per-project unique identifier
     """
     def __init__(self, project, id = None):
+        assert isinstance(project, Project)
         self.project = project
         self.id      = id
 
@@ -416,6 +448,7 @@
                        its homedirectory
     """
     def __init__(self, project, directory):
+        assert isinstance(directory, str)
         Output.__init__(self, project, OUTPUT_ID_HOME)
         self.directory = directory
 
@@ -431,6 +464,7 @@
                 added 
     """
     def __init__(self, project, name, id = None, add_to_bootclass_path = False ):
+        assert isinstance(name, str)
         Output.__init__(self, project, id)
         self.name = name
         self.add_to_bootclass_path = add_to_bootclass_path

Modified: gump/branches/Gump3/pygump/python/gump/test/testModel.py
URL: http://svn.apache.org/viewcvs/gump/branches/Gump3/pygump/python/gump/test/testModel.py?view=diff&r1=156254&r2=156255
==============================================================================
--- gump/branches/Gump3/pygump/python/gump/test/testModel.py (original)
+++ gump/branches/Gump3/pygump/python/gump/test/testModel.py Sat Mar  5 07:15:02 2005
@@ -29,6 +29,18 @@
 from gump.model import CVS_METHOD_PSERVER
 from gump.model import SvnRepository
 from gump.model import Project
+from gump.model import CvsModule
+from gump.model import SvnModule
+from gump.model import Dependency
+from gump.model import DEPENDENCY_INHERIT_ALL
+from gump.model import Command
+from gump.model import Output
+from gump.model import Mkdir
+from gump.model import Rmdir
+from gump.model import Script
+from gump.model import Homedir
+from gump.model import OUTPUT_ID_HOME
+from gump.model import Jar
 
 class ModelTestCase(TestCase):
     def setUp(self):
@@ -232,6 +244,319 @@
         self.assertRaises(AssertionError, m.add_project, p)
         self.assertEqual(1,len(m.projects))
         
+    def test_cvs_module(self):
+        wname = "blah"
+        w = Workspace(wname)
+        rname = "booh"
+        r = Repository(w,rname)
+        
+        url = "http://www.somewhere.org/bweh/"
+        description = "Bweh is foo bar blah."
+        tag = "VERSION_1_0"
+        
+        name = "bweh"
+        m = CvsModule(r,name,tag,url,description)
+        self.assertEqual(r, m.repository)
+        self.assertEqual(name,m.name)
+        self.assertEqual(tag,m.tag)
+        self.assertEqual(url,m.url)
+        self.assertEqual(description,m.description)
+        self.assertEqual({}, m.projects)
+        
+        m = CvsModule(r,name,tag=tag)
+        self.assertEqual(tag,m.tag)
+
+    def test_svn_module(self):
+        wname = "blah"
+        w = Workspace(wname)
+        rname = "booh"
+        r = Repository(w,rname)
+        
+        url = "http://www.somewhere.org/bweh/"
+        description = "Bweh is foo bar blah."
+        path = "some/where"
+        
+        name = "bweh"
+        m = SvnModule(r,name,path,url,description)
+        self.assertEqual(r, m.repository)
+        self.assertEqual(name,m.name)
+        self.assertEqual(path,m.path)
+        self.assertEqual(url,m.url)
+        self.assertEqual(description,m.description)
+        self.assertEqual({}, m.projects)
+        
+    def test_project(self):
+        wname = "blah"
+        w = Workspace(wname)
+        rname = "booh"
+        r = Repository(w,rname)
+        mname = "bweh"
+        m = Module(r,mname)
+        
+        name = "bwop"
+        p = Project(m,name)
+        self.assertEqual(m, p.module)
+        self.assertEqual(name,p.name)
+        self.assertEqual([],p.dependees)
+        self.assertEqual([],p.dependencies)
+        self.assertEqual([],p.commands)
+        self.assertEqual([],p.outputs)
+        
+        self.assertRaises(AssertionError, Project, None, name)
+        self.assertRaises(AssertionError, Project, name, None)
+        self.assertRaises(AssertionError, Project, "wrong", name)
+        self.assertRaises(AssertionError, Project, m, m)
+        
+        # note that dependencies are tested in test_dependencies...
+        
+        c = Command(p)
+        p.add_command(c)
+        self.assertEqual(c,p.commands[0])
+        self.assertEqual(1,len(p.commands))
+        p.add_command(c)
+        self.assertEqual(c,p.commands[1])
+        self.assertEqual(2,len(p.commands))
+        
+        self.assertRaises(AssertionError,p.add_command,None)
+        self.assertRaises(AssertionError,p.add_command,"stop!")
+        
+        o = Output(p)
+        p.add_output(o)
+        self.assertEqual(o,p.outputs[0])
+        self.assertEqual(1,len(p.outputs))
+        p.add_output(o)
+        self.assertEqual(o,p.outputs[1])
+        self.assertEqual(2,len(p.outputs))
+    
+        self.assertRaises(AssertionError,p.add_output,None)
+        self.assertRaises(AssertionError,p.add_output,"jarfile!")
+        
+    def test_dependencies(self):
+        wname = "blah"
+        w = Workspace(wname)
+        rname = "booh"
+        r = Repository(w,rname)
+        mname = "bweh"
+        m = Module(r,mname)
+        #      A
+        #      ^
+        #      |
+        #     / \
+        #    B<--C
+        a = Project(m,"A")
+        b = Project(m,"B")
+        c = Project(m,"C")
+        
+        d1 = Dependency(b,c) # c -> b
+        d2 = Dependency(a,c) # c -> a
+        d3 = Dependency(a,b) # b -> a
+        
+        c.add_dependency(d1) # c -> b
+        self.assertEqual(d1,c.dependencies[0])
+        self.assertEqual(1,len(c.dependencies))
+        self.assertEqual(0,len(c.dependees))
+        self.assertEqual(d1,b.dependees[0])
+        self.assertEqual(0,len(b.dependencies))
+        self.assertEqual(1,len(b.dependees))
+        
+        c.add_dependency(d2) # c -> a
+        self.assertEqual(d2,c.dependencies[1])
+        self.assertEqual(2,len(c.dependencies))
+        self.assertEqual(0,len(c.dependees))
+        self.assertEqual(d2,a.dependees[0])
+        self.assertEqual(0,len(a.dependencies))
+        self.assertEqual(1,len(a.dependees))
+
+        b.add_dependency(d3) # b -> a
+        self.assertEqual(d3,b.dependencies[0])
+        self.assertEqual(1,len(b.dependencies))
+        self.assertEqual(1,len(b.dependees))
+        self.assertEqual(d3,a.dependees[1])
+        self.assertEqual(0,len(a.dependencies))
+        self.assertEqual(2,len(a.dependees))
+        
+        self.assertRaises(AssertionError, c.add_dependency, None)
+        self.assertRaises(AssertionError, c.add_dependency, "blaaaa")
+        self.assertRaises(AssertionError, c.add_dependency, b)
+        self.assertEqual(2,len(c.dependencies))
+        self.assertEqual(0,len(c.dependees))
+        
+        optional = True
+        runtime = True
+        inherit = DEPENDENCY_INHERIT_ALL
+        specific_output_id = "some-sub-project-jar"
+        d = Dependency(c,b,optional,runtime,inherit,specific_output_id)
+        self.assertEqual(c,d.dependency)
+        self.assertEqual(b,d.dependee)
+        self.assertEqual(optional,d.optional)
+        self.assertEqual(inherit,d.inherit)
+        self.assertEqual(specific_output_id,d.specific_output_id)
+        
+        d = Dependency(dependency=c,dependee=b,optional=False)
+        self.assertEqual(c,d.dependency)
+        self.assertEqual(b,d.dependee)
+        self.assertEqual(False,d.optional)
+        
+        d = Dependency(dependency=c,dependee=b,inherit=False)
+        self.assertEqual(c,d.dependency)
+        self.assertEqual(b,d.dependee)
+        self.assertEqual(False,d.inherit)
+        
+        d = Dependency(dependency=c,dependee=b,specific_output_id="blah")
+        self.assertEqual(c,d.dependency)
+        self.assertEqual(b,d.dependee)
+        self.assertEqual("blah",d.specific_output_id)
+        
+        self.assertRaises(AssertionError,Dependency,None,c)
+        self.assertRaises(AssertionError,Dependency,c,None)
+        self.assertRaises(AssertionError,Dependency,"B",c)
+        self.assertRaises(AssertionError,Dependency,c,"B")
+    
+    def test_command(self):
+        wname = "blah"
+        w = Workspace(wname)
+        rname = "booh"
+        r = Repository(w,rname)
+        mname = "bweh"
+        m = Module(r,mname)
+        pname = "bwop"
+        p = Project(m,pname)
+        
+        c = Command(p)
+        self.assertEqual(p,c.project)
+        self.assertRaises(AssertionError,Command,None)
+        self.assertRaises(AssertionError,Command,"someproject")
+        
+    def test_mkdir(self):
+        wname = "blah"
+        w = Workspace(wname)
+        rname = "booh"
+        r = Repository(w,rname)
+        mname = "bweh"
+        m = Module(r,mname)
+        pname = "bwop"
+        p = Project(m,pname)
+        
+        dir = "some/dir"
+        c = Mkdir(p,dir)
+        self.assertEqual(dir,c.directory)
+        
+        self.assertRaises(AssertionError,Mkdir,None,c)
+        self.assertRaises(AssertionError,Mkdir,"someproject",c)
+        self.assertRaises(AssertionError,Mkdir,p,None)
+        self.assertRaises(AssertionError,Mkdir,p,p)
+
+    def test_rmdir(self):
+        wname = "blah"
+        w = Workspace(wname)
+        rname = "booh"
+        r = Repository(w,rname)
+        mname = "bweh"
+        m = Module(r,mname)
+        pname = "bwop"
+        p = Project(m,pname)
+        
+        dir = "some/dir"
+        c = Rmdir(p,dir)
+        self.assertEqual(dir,c.directory)
+        
+        self.assertRaises(AssertionError,Rmdir,None,c)
+        self.assertRaises(AssertionError,Rmdir,"someproject",c)
+        self.assertRaises(AssertionError,Rmdir,p,None)
+        self.assertRaises(AssertionError,Rmdir,p,p)
+
+    def test_script(self):
+        wname = "blah"
+        w = Workspace(wname)
+        rname = "booh"
+        r = Repository(w,rname)
+        mname = "bweh"
+        m = Module(r,mname)
+        pname = "bwop"
+        p = Project(m,pname)
+        
+        name = "build"
+        args = ["-d", "some/dir"]
+        c = Script(p,name, args)
+        self.assertEqual(name,c.name)
+        self.assertEqual(args,c.args)
+        c = Script(p,name)
+        self.assertEqual(name,c.name)
+        self.assertEqual([],c.args)
+        
+        self.assertRaises(AssertionError,Script,None,c)
+        self.assertRaises(AssertionError,Script,"someproject",c)
+        self.assertRaises(AssertionError,Script,p,None)
+        self.assertRaises(AssertionError,Script,p,name,None)
+        self.assertRaises(AssertionError,Script,p,name,"blah")
+        self.assertRaises(AssertionError,Script,p,name,[p])
+
+    def test_output(self):
+        wname = "blah"
+        w = Workspace(wname)
+        rname = "booh"
+        r = Repository(w,rname)
+        mname = "bweh"
+        m = Module(r,mname)
+        pname = "bwop"
+        p = Project(m,pname)
+        
+        o = Output(p)
+        self.assertEqual(p,o.project)
+        self.assertRaises(AssertionError,Output,None)
+        self.assertRaises(AssertionError,Output,"someproject")
+        
+    def test_homedir(self):
+        wname = "blah"
+        w = Workspace(wname)
+        rname = "booh"
+        r = Repository(w,rname)
+        mname = "bweh"
+        m = Module(r,mname)
+        pname = "bwop"
+        p = Project(m,pname)
+        
+        dir = "some/dir"
+        o = Homedir(p,dir)
+        self.assertEqual(p,o.project)
+        self.assertEqual(dir,o.directory)
+        self.assertEqual(OUTPUT_ID_HOME,o.id)
+        self.assertRaises(AssertionError,Homedir,None,dir)
+        self.assertRaises(AssertionError,Homedir,"someproject",dir)
+        self.assertRaises(AssertionError,Homedir,p,None)
+        self.assertRaises(AssertionError,Homedir,p,p)
+        
+    def test_jar(self):
+        wname = "blah"
+        w = Workspace(wname)
+        rname = "booh"
+        r = Repository(w,rname)
+        mname = "bweh"
+        m = Module(r,mname)
+        pname = "bwop"
+        p = Project(m,pname)
+        
+        jar = "my.jar"
+        o = Jar(p,jar)
+        self.assertEqual(p,o.project)
+        self.assertEqual(jar,o.name)
+        self.assertRaises(AssertionError,Jar,None,jar)
+        self.assertRaises(AssertionError,Jar,"someproject",jar)
+        self.assertRaises(AssertionError,Jar,p,None)
+        self.assertRaises(AssertionError,Jar,p,p)
+        
+        id = "blah"
+        bootclass = True
+        o = Jar(p, jar, id, bootclass)
+        self.assertEqual(p,o.project)
+        self.assertEqual(jar,o.name)
+        self.assertEqual(id,o.id)
+        self.assertEqual(bootclass,o.add_to_bootclass_path)
+
+        o = Jar(p, jar, id=id)
+        self.assertEqual(id,o.id)
+        o = Jar(p, jar, add_to_bootclass_path=bootclass)
+        self.assertEqual(bootclass,o.add_to_bootclass_path)
         
 
 # this is used by testrunner.py to determine what tests to run



Mime
View raw message