Part of my attempt now involves cleaning up config; this means for me; removing the...
authorAlec Warner <antarus@gentoo.org>
Wed, 7 Mar 2007 06:38:05 +0000 (06:38 -0000)
committerAlec Warner <antarus@gentoo.org>
Wed, 7 Mar 2007 06:38:05 +0000 (06:38 -0000)
svn path=/main/trunk/; revision=6190

pym/portage/env/__init__.py [new file with mode: 0644]
pym/portage/env/config.py [new file with mode: 0644]
pym/portage/tests/__init__.py
pym/portage/tests/dep/test_isvalidatom.py
pym/portage/tests/env/__init__.py [new file with mode: 0644]
pym/portage/tests/env/config/__init__.py [new file with mode: 0644]
pym/portage/tests/env/config/test_PackageKeywordsFile.py [new file with mode: 0644]

diff --git a/pym/portage/env/__init__.py b/pym/portage/env/__init__.py
new file mode 100644 (file)
index 0000000..63f6f9e
--- /dev/null
@@ -0,0 +1,4 @@
+# Copyright: 2007 Gentoo Foundation
+# License: GPL2
+# $Id$
+
diff --git a/pym/portage/env/config.py b/pym/portage/env/config.py
new file mode 100644 (file)
index 0000000..05bb492
--- /dev/null
@@ -0,0 +1,60 @@
+# config.py -- Portage Config
+# Copyright 2007 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+# $Id$
+
+import os
+from UserDict import UserDict
+
+class PackageKeywords(UserDict):
+       """
+       A base class stub for things to inherit from; some people may want a database based package.keywords or something
+       
+       Internally dict has pairs of the form
+       {'cpv':['key1','key2','key3'...]
+       """
+       
+       data = {}
+       
+       def iteritems(self):
+               return self.data.iteritems()
+       
+       def keys(self):
+               return self.data.keys()
+       
+       def __contains__(self, other):
+               return other in self.data
+       
+       def __hash__( self ):
+               return self.data.__hash__()
+       
+class PackageKeywordsFile(PackageKeywords):
+       """
+       Inherits from PackageKeywords; implements a file-based backend.  Doesn't handle recursion yet.
+       """
+       def __init__( self, filename ):
+               self.fname = filename
+       
+       def load(self, recursive=False):
+               """
+               Package.keywords files have comments that begin with #.
+               The entries are of the form:
+               >>> cpv [-~]keyword1 [-~]keyword2 keyword3
+               >>> Exceptions include -*, ~*, and ** for keywords.
+               """
+               
+               if os.path.exists( self.fname ):
+                       f = open(self.fname, 'rb')
+                       for line in f:
+                               if line.startswith('#'):
+                                       continue
+                               split = line.split()
+                               if len(split):
+                                       # Surprisingly this works for iterables of length 1
+                                       # fex ['sys-apps/portage','x86','amd64'] becomes {'sys-apps/portage':['x86','amd64']}
+                                       key, items = split[0],split[1:]
+                                       # if they specify the same cpv twice; stack the values (append) instead of overwriting.
+                                       if key in self.data:
+                                               self.data[key].append(items)
+                                       else:
+                                               self.data[key] = items
index 159e67b63bf666016f42087306e76f6b55dfe0c9..7d13af1e6cc7a4f55ab9afb30c5e4f00a9d377ef 100644 (file)
@@ -7,7 +7,7 @@ import os, unittest, time
 import portage.tests
 
 def main():
-       testDirs = ["util","versions", "dep", "xpak"]
+       testDirs = ["util","versions", "dep", "xpak", "env/config"]
        suite = unittest.TestSuite()
        basedir = os.path.dirname(__file__)
        for mydir in testDirs:
@@ -37,13 +37,10 @@ def getTests( path, base_path ):
        parent_module = parent_module.replace('/','.')
        result = []
        for mymodule in files:
-               try:
-                       # Make the trailing / a . for module importing
-                       modname = ".".join((parent_module, mymodule))
-                       mod = my_import(modname)
-                       result.append( unittest.TestLoader().loadTestsFromModule(mod) )
-               except ImportError:
-                       raise
+               # Make the trailing / a . for module importing
+               modname = ".".join((parent_module, mymodule))
+               mod = my_import(modname)
+               result.append( unittest.TestLoader().loadTestsFromModule(mod) )
        return result
 
 class TextTestResult(unittest._TextTestResult):
@@ -87,6 +84,7 @@ class TestCase(unittest.TestCase):
                # _testMethodName.
                self._testMethodName = methodName
                unittest.TestCase.__init__(self, methodName)
+               self.todo = False
                
        def defaultTestResult(self):
                return TextTestResult()
index 35f7160b79a8aa97039bba6afbaace1cc97b5704..512d9b4656005588d102589197c6e5991540ab8a 100644 (file)
@@ -12,10 +12,9 @@ class IsValidAtom(TestCase):
        """ A simple testcase for isvalidatom
        """
 
-       todo = True
-
        def testIsValidAtom(self):
-               
+       
+               self.todo = True        
                tests = [ ( "sys-apps/portage", True ),
                          ( "=sys-apps/portage-2.1", True ),
                          ( "=sys-apps/portage-2.1*", True ),
diff --git a/pym/portage/tests/env/__init__.py b/pym/portage/tests/env/__init__.py
new file mode 100644 (file)
index 0000000..50e38af
--- /dev/null
@@ -0,0 +1,5 @@
+# tests/portage/env/__init__.py -- Portage Unit Test functionality
+# Copyright 2007 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+# $Id$
+
diff --git a/pym/portage/tests/env/config/__init__.py b/pym/portage/tests/env/config/__init__.py
new file mode 100644 (file)
index 0000000..7fc0d0e
--- /dev/null
@@ -0,0 +1,5 @@
+# tests/portage/env/config/__init__.py -- Portage Unit Test functionality
+# Copyright 2007 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+# $Id$
+
diff --git a/pym/portage/tests/env/config/test_PackageKeywordsFile.py b/pym/portage/tests/env/config/test_PackageKeywordsFile.py
new file mode 100644 (file)
index 0000000..f39ef96
--- /dev/null
@@ -0,0 +1,35 @@
+# test_PackageKeywordsFile.py -- Portage Unit Testing Functionality
+# Copyright 2006 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+# $Id: test_PackageKeywordsFile.py 6182 2007-03-06 07:35:22Z antarus $
+
+from portage.tests import TestCase
+from portage.env.config import PackageKeywordsFile
+
+class PackageKeywordsFileTestCase(TestCase):
+
+       fname = 'package.keywords'
+       cpv = 'sys-apps/portage'
+       keywords = ['~x86', 'amd64', '-mips']
+       
+       def testPackageKeywordsLoad(self):
+               """
+               A simple test to ensure the load works properly
+               """
+
+               self.BuildFile()
+               f = PackageKeywordsFile(self.fname)
+               f.load()
+               for cpv, keyword in f.iteritems():
+                       self.assertEqual( cpv, self.cpv )
+                       [k for k in keyword if self.assertTrue(k in self.keywords)]
+               self.NukeFile()
+       
+       def BuildFile(self):
+               f = open(self.fname, 'wb')
+               f.write('%s %s\n' % (self.cpv, ' '.join(self.keywords)))
+               f.close()
+
+       def NukeFile(self):
+               import os
+               os.unlink(self.fname)