summaryrefslogtreecommitdiff
path: root/setuptools/tests/__init__.py
diff options
context:
space:
mode:
authorpje <pje@571e12c6-e1fa-0310-aee7-ff1267fa46bd>2004-03-08 20:07:25 +0000
committerpje <pje@571e12c6-e1fa-0310-aee7-ff1267fa46bd>2004-03-08 20:07:25 +0000
commit671ad4f0084ed52c4881701aa7902a1fc0908c91 (patch)
treed5bce71d617b8a4cd53a95e9fd7c91c6a7401b19 /setuptools/tests/__init__.py
parent733278535499d7b3b63def2cc0d7961d1e071062 (diff)
downloadwsgiref-671ad4f0084ed52c4881701aa7902a1fc0908c91.tar.gz
Added basic 'Require()' class that can check whether a requirement is
installed in a particular location or set of locations, and up-to-date. Smart defaults make most version checks trivial, e.g.: Require('Something','1.2','some.thing').is_current() Require('Other',None,'other.thing',attribute='someFunc').is_current() Require('Existentialism',None,'existenz').is_current() The first line checks whether the 'some.thing' module defines a '__version__' constant that compares >='1.2' (using smart version parsing from 'distutils.version'). The second checks whether 'other.thing' defines 'someFunc'. (This latter form ('requested_version=None') is used to do version sniffing on modules that don't define a version attribute.) The third format just checks for the existence of the named module. git-svn-id: svn://svn.eby-sarna.com/svnroot/wsgiref@238 571e12c6-e1fa-0310-aee7-ff1267fa46bd
Diffstat (limited to 'setuptools/tests/__init__.py')
-rw-r--r--setuptools/tests/__init__.py84
1 files changed, 83 insertions, 1 deletions
diff --git a/setuptools/tests/__init__.py b/setuptools/tests/__init__.py
index 7a5534f..0c4a4f1 100644
--- a/setuptools/tests/__init__.py
+++ b/setuptools/tests/__init__.py
@@ -7,7 +7,11 @@ from distutils.errors import DistutilsSetupError
import setuptools, setuptools.dist
from setuptools import Feature
from distutils.core import Extension
+from setuptools.depends import extract_constant, get_module_constant
+from setuptools.depends import find_module, Require
+from distutils.version import StrictVersion, LooseVersion
+import sys, os.path
def makeSetup(**args):
"""Return distribution from 'setup(**args)', without executing commands"""
@@ -35,6 +39,84 @@ def makeSetup(**args):
+class DependsTests(TestCase):
+
+ def testExtractConst(self):
+
+ from setuptools.depends import extract_constant
+
+ def f1():
+ global x,y,z
+ x = "test"
+ y = z
+
+ # unrecognized name
+ self.assertEqual(extract_constant(f1.func_code,'q', -1), None)
+
+ # constant assigned
+ self.assertEqual(extract_constant(f1.func_code,'x', -1), "test")
+
+ # expression assigned
+ self.assertEqual(extract_constant(f1.func_code,'y', -1), -1)
+
+ # recognized name, not assigned
+ self.assertEqual(extract_constant(f1.func_code,'z', -1), None)
+
+
+ def testFindModule(self):
+ self.assertRaises(ImportError, find_module, 'no-such.-thing')
+ self.assertRaises(ImportError, find_module, 'setuptools.non-existent')
+ f,p,i = find_module('setuptools.tests'); f.close()
+
+ def testModuleExtract(self):
+ from distutils import __version__
+ self.assertEqual(
+ get_module_constant('distutils','__version__'), __version__
+ )
+ self.assertEqual(
+ get_module_constant('sys','version'), sys.version
+ )
+ self.assertEqual(
+ get_module_constant('setuptools.tests','__doc__'),__doc__
+ )
+
+ def testRequire(self):
+ req = Require('Distutils','1.0.3','distutils')
+
+ self.assertEqual(req.name, 'Distutils')
+ self.assertEqual(req.module, 'distutils')
+ self.assertEqual(req.requested_version, '1.0.3')
+ self.assertEqual(req.attribute, '__version__')
+
+ from distutils import __version__
+ self.assertEqual(req.get_version(), __version__)
+
+ self.failUnless(req.is_present())
+ self.failUnless(req.is_current())
+
+ req = Require('Distutils 3000','03000','distutils',format=LooseVersion)
+ self.failUnless(req.is_present())
+ self.failIf(req.is_current())
+
+ req = Require('Do-what-I-mean','1.0','d-w-i-m')
+ self.failIf(req.is_present())
+ self.failIf(req.is_current())
+
+ req = Require('Tests', None, 'tests')
+ self.assertEqual(req.format, None)
+ self.assertEqual(req.attribute, None)
+ self.assertEqual(req.requested_version, None)
+
+ paths = [os.path.dirname(p) for p in __path__]
+ self.failUnless(req.is_present(paths))
+ self.failUnless(req.is_current(paths))
+
+
+
+
+
+
+
@@ -285,7 +367,7 @@ class TestCommandTests(TestCase):
-testClasses = (DistroTests, FeatureTests, TestCommandTests)
+testClasses = (DependsTests, DistroTests, FeatureTests, TestCommandTests)
def test_suite():
return TestSuite([makeSuite(t,'test') for t in testClasses])