--- /dev/null
+# Copyright: 2007 Gentoo Foundation
+# License: GPL2
+# $Id$
+
--- /dev/null
+# 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
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:
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):
# _testMethodName.
self._testMethodName = methodName
unittest.TestCase.__init__(self, methodName)
+ self.todo = False
def defaultTestResult(self):
return TextTestResult()
""" 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 ),
--- /dev/null
+# 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$
+
--- /dev/null
+# 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$
+
--- /dev/null
+# 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)