[Zope-CVS] CVS: Packages/zpkgtools/zpkgtools/tests -
test_app.py:1.9 test_include.py:1.12 test_loader.py:1.2
Fred L. Drake, Jr.
fred at zope.com
Fri Apr 23 15:56:14 EDT 2004
Update of /cvs-repository/Packages/zpkgtools/zpkgtools/tests
In directory cvs.zope.org:/tmp/cvs-serv17724/zpkgtools/tests
Modified Files:
test_app.py test_include.py test_loader.py
Log Message:
change the PACKAGE.cfg file to include three sections instead of two; the
<load> section is used to load files from external sources into the
collection, the <collection> section describes what files to include and
exclude from the component, and the <distribution> section describes what
to include in the distribution root
this required a lot of internal changes
=== Packages/zpkgtools/zpkgtools/tests/test_app.py 1.8 => 1.9 ===
--- Packages/zpkgtools/zpkgtools/tests/test_app.py:1.8 Tue Apr 20 14:53:42 2004
+++ Packages/zpkgtools/zpkgtools/tests/test_app.py Fri Apr 23 15:56:13 2004
@@ -211,7 +211,7 @@
"-f", "-m", self.mapfile, "-v1.0",
"collection:application"]
options = app.parse_args(argv)
- application = app.Application(options)
+ application = app.BuilderApplication(options)
self.assertEqual(application.resource_type, "collection")
#
application.load_resource()
=== Packages/zpkgtools/zpkgtools/tests/test_include.py 1.11 => 1.12 ===
--- Packages/zpkgtools/zpkgtools/tests/test_include.py:1.11 Mon Apr 19 11:38:24 2004
+++ Packages/zpkgtools/zpkgtools/tests/test_include.py Fri Apr 23 15:56:13 2004
@@ -23,8 +23,8 @@
from os.path import join
from StringIO import StringIO
-from zpkgtools import cvsloader
from zpkgtools import include
+from zpkgtools import loader
class InclusionProcessorTestCase(unittest.TestCase):
@@ -32,7 +32,8 @@
def setUp(self):
self.source = os.path.dirname(__file__)
self.destination = tempfile.mkdtemp(prefix="test_include_")
- self.processor = include.InclusionProcessor(self.source)
+ self.loader = loader.Loader()
+ self.processor = include.InclusionProcessor(self.source, self.loader)
self.source = os.path.abspath(self.source)
self.files_written = []
@@ -53,30 +54,45 @@
def test_simple_includespec(self):
self.write_file(include.PACKAGE_CONF, """\
- <collection>
- # This is a comment. It should be ignored.
+ <load>
+ # Load files from external sources into the collection space:
foo.html http://www.python.org/index.html
doc/whatzit.txt repository:doc/whatzit.txt
+ </load>
+ <collection>
+ # This is a comment. It should be ignored.
+
+ # Don't include ignorethis.txt in the distributed collection:
ignorethis.txt -
+ # Include ignorethis.txt as newname1.txt and newname2.txt
+ # in the distributed collection:
+ newname1.txt ignorethis.txt
+ newname2.txt ignorethis.txt
+
# Another comment.
</collection>
<distribution>
# A comment.
+
+ # Copy the collection's source.txt to the distribution's
+ # destination.txt; source.txt will still be included in
+ # the distributed collection.
destination.txt source.txt
</distribution>
""")
- coll, dest = include.load(self.source)
- self.assertEqual(len(coll.excludes), 2)
- self.assertEqual(len(coll.includes), 2)
+ specs = include.load(self.source)
+ specs.collection.cook()
+ self.assertEqual(len(specs.collection.excludes), 2)
+ self.assertEqual(len(specs.collection.includes), 2)
self.assert_(join(self.source, "ignorethis.txt")
- in coll.excludes)
+ in specs.collection.excludes)
self.assert_(join(self.source, include.PACKAGE_CONF)
- in coll.excludes)
- self.assertEqual(coll.includes["foo.html"],
- "http://www.python.org/index.html")
- self.assertEqual(coll.includes[join("doc", "whatzit.txt")],
+ in specs.collection.excludes)
+ self.assertEqual(specs.collection.includes["newname1.txt"],
+ "ignorethis.txt")
+ self.assertEqual(specs.loads.includes[join("doc", "whatzit.txt")],
"repository:doc/whatzit.txt")
def test_error_on_nonexistant_ignore(self):
@@ -85,12 +101,13 @@
does-not-exist.txt -
</collection>
""")
+ specs = include.load(self.source)
try:
- include.load(self.source)
+ specs.collection.cook()
except include.InclusionSpecificationError, e:
self.assertEqual(e.filename,
join(self.source, include.PACKAGE_CONF))
- self.assertEqual(e.lineno, 2)
+ #self.assertEqual(e.lineno, 2)
else:
self.fail("expected InclusionSpecificationError")
@@ -101,7 +118,7 @@
</collection>
""")
try:
- coll, dist = include.load(self.source)
+ include.load(self.source)
except include.InclusionSpecificationError, e:
self.assertEqual(e.filename,
join(self.source, include.PACKAGE_CONF))
@@ -115,19 +132,43 @@
*.txt -
</collection>
""")
- coll, dist = include.load(self.source)
- self.assertEqual(len(coll.excludes), 2)
+ specs = include.load(self.source)
+ specs.collection.cook()
+ self.assertEqual(len(specs.collection.excludes), 2)
self.assert_(join(self.source, "ignorethis.txt")
- in coll.excludes)
+ in specs.collection.excludes)
self.assert_(join(self.source, include.PACKAGE_CONF)
- in coll.excludes)
+ in specs.collection.excludes)
def test_disallow_exclude_in_distribution_spec(self):
- self.write_file(include.PACKAGE_CONF, """\
- <distribution>
+ self.check_disallow_exclude_in_spec("distribution")
+
+ def test_disallow_exclude_in_load_spec(self):
+ self.check_disallow_exclude_in_spec("load")
+
+ def check_disallow_exclude_in_spec(self, sectionname):
+ text = """\
+ <%s>
ignorethis.txt -
- </distribution>
- """)
+ </%s>
+ """ % (sectionname, sectionname)
+ self.write_file(include.PACKAGE_CONF, text)
+ self.assertRaises(include.InclusionSpecificationError,
+ include.load, self.source)
+
+ def test_disallow_external_reference_in_collection_spec(self):
+ self.check_disallow_external_reference_in_spec("collection")
+
+ def test_disallow_external_reference_in_distribution_spec(self):
+ self.check_disallow_external_reference_in_spec("distribution")
+
+ def check_disallow_external_reference_in_spec(self, sectionname):
+ text = """\
+ <%s>
+ external.txt http://example.net/some/where/else.txt
+ </%s>
+ """ % (sectionname, sectionname)
+ self.write_file(include.PACKAGE_CONF, text)
self.assertRaises(include.InclusionSpecificationError,
include.load, self.source)
@@ -146,28 +187,28 @@
def check_normalize_paths(self, normalize):
INCLUDES = "INCLUDES.txt"
- self.assertEqual(normalize("README.txt", "t"),
+ self.assertEqual(normalize("README.txt", "t", "group"),
"README.txt")
- self.assertEqual(normalize("doc/README.txt", "t"),
+ self.assertEqual(normalize("doc/README.txt", "t", "group"),
join("doc", "README.txt"))
# Ignore this because it looks like a Windows drive letter:
self.assertRaises(include.InclusionSpecificationError,
- normalize, "c:foo/bar", "t")
+ normalize, "c:foo/bar", "t", "group")
# Absolute paths are an error as well:
self.assertRaises(include.InclusionSpecificationError,
- normalize, "/absolute/path", "t")
+ normalize, "/absolute/path", "t", "group")
# Relative paths that point up the hierarchy are also disallowed:
self.assertRaises(include.InclusionSpecificationError,
- normalize, "abc/../../def.txt", "t")
+ normalize, "abc/../../def.txt", "t", "group")
self.assertRaises(include.InclusionSpecificationError,
- normalize, "../def.txt", "t")
+ normalize, "../def.txt", "t", "group")
def check_normalize_urls(self, normalize):
INCLUDES = "INCLUDES.txt"
for url in ("http://www.example.com/index.html",
"repository:/Zope3/doc",
"cvs://cvs.zope.com/cvs-repository:/Zope3/doc:HEAD"):
- self.assertEqual(normalize(url, "t"), url)
+ self.assertEqual(normalize(url, "t", "group"), url)
def test_createDistributionTree_creates_destination(self):
os.rmdir(self.destination)
@@ -181,8 +222,10 @@
__init__.py -
</collection>
""")
- coll, dist = include.load(self.source)
- self.processor.createDistributionTree(self.destination, coll)
+ specs = include.load(self.source)
+ specs.collection.cook()
+ self.processor.createDistributionTree(self.destination,
+ specs.collection)
self.check_file("ignorethis.txt")
self.check_file("somescript.py")
self.assert_(not os.path.exists(join(self.destination, "__init__.py")))
@@ -201,37 +244,35 @@
def test_including_from_cvs_url(self):
self.start_including_from_cvs_url()
- self.processor.addSingleInclude(
- "somedir",
- "cvs://cvs.zope.org:pserver/cvs-repository:Zope3",
- self.destination)
- cvsurl, destination = self.args
- self.assertEqual(cvsurl.getUrl(),
- "cvs://cvs.zope.org:pserver/cvs-repository:Zope3")
- self.assertEqual(destination,
- join(self.destination, "somedir"))
+ URL = "cvs://anonymous@cvs.zope.org:pserver/cvs-repository:Zope3"
+ self.processor.addSingleInclude("somedir", URL, self.destination)
+ url, = self.args[0]
+ self.assertEqual(url, URL)
+ path, dest = self.args[1]
+ self.assertEqual(path, self.return_path)
def test_including_from_cvs_url_without_base(self):
self.start_including_from_cvs_url()
- self.processor.addSingleInclude(
- "somedir",
- "cvs://cvs.zope.org:pserver/cvs-repository:Zope3",
- self.destination)
- cvsurl, destination = self.args
- self.assertEqual(cvsurl.getUrl(),
- "cvs://cvs.zope.org:pserver/cvs-repository:Zope3")
- self.assertEqual(destination,
- join(self.destination, "somedir"))
+ URL = "cvs://anonymous@cvs.zope.org:pserver/cvs-repository:Zope3"
+ self.processor.addSingleInclude("somedir", URL, self.destination)
+ url, = self.args[0]
+ self.assertEqual(url, URL)
+ path, dest = self.args[1]
+ self.assertEqual(path, self.return_path)
def start_including_from_cvs_url(self):
- self.processor.includeFromUrl = lambda src, dst: self.fail(
- "not expected to load via URL")
- self.processor.includeFromLocalTree = lambda src, dst: self.fail(
- "not expected to load from local tree")
- self.processor.includeFromCvs = self.save_args
+ # We just want to make sure the loader and processor get
+ # called with the right stuff:
+ self.loader.load_cvs = self.save_args
+ self.processor.includeFromLocalTree = self.save_args
+ self.args = []
+
+ return_path = "/tmp/junk-42"
def save_args(self, *args):
- self.args = args
+ self.args.append(args)
+ self.loader.add_working_dir(args[0], None, self.return_path, False)
+ return self.return_path
def test_including_from_repository_url_without_base(self):
# When using a repository: URL, there must be a base cvs: URL
@@ -269,10 +310,6 @@
# This also tests the automatic creation of a required output
# directory.
FILENAME = "ignorethis.txt"
- self.processor.includeFromCvs = lambda src, dst: self.fail(
- "not expected to load from CVS")
- self.processor.includeFromUrl = lambda src, dst: self.fail(
- "not expected to load via URL")
self.processor.addSingleInclude("foo/splat.txt",
FILENAME,
self.destination)
=== Packages/zpkgtools/zpkgtools/tests/test_loader.py 1.1 => 1.2 ===
--- Packages/zpkgtools/zpkgtools/tests/test_loader.py:1.1 Mon Apr 19 23:37:24 2004
+++ Packages/zpkgtools/zpkgtools/tests/test_loader.py Fri Apr 23 15:56:13 2004
@@ -13,10 +13,12 @@
##############################################################################
"""Tests for the zpkgtools.loader module."""
+import filecmp
import os
import shutil
import tempfile
import unittest
+import urllib
from zpkgtools import loader
@@ -31,8 +33,115 @@
def tearDown(self):
shutil.rmtree(self.workingdir)
+ def createLoader(self, tag=None):
+ return loader.Loader(tag)
-class DummyLoader:
+
+class LoaderTestCase(LoaderTestBase):
+
+ def test_transform_url_with_default_tag(self):
+ convert = loader.Loader("TAG").transform_url
+ self.check_unchanging_urls(convert)
+ eq = self.assertEqual
+ # cvs:
+
+ # repository:
+ eq(convert("repository::"),
+ "repository::TAG")
+ eq(convert("repository:path"),
+ "repository:path:TAG")
+ eq(convert("repository:/some/path/:"),
+ "repository:/some/path/:TAG")
+
+ def test_transform_url_without_default_tag(self):
+ convert = loader.Loader().transform_url
+ self.check_unchanging_urls(convert)
+ eq = self.assertEqual
+
+ def check_unchanging_urls(self, convert):
+ eq = self.assertEqual
+ eq(convert("http://example.org/foo/bar.txt"),
+ "http://example.org/foo/bar.txt")
+ eq(convert("https://example.org/foo/bar.txt"),
+ "https://example.org/foo/bar.txt")
+ eq(convert("file://localhost/path/to/somewhere.py"),
+ "file://localhost/path/to/somewhere.py")
+ eq(convert("file:///path/to/somewhere.py"),
+ "file:///path/to/somewhere.py")
+ eq(convert("cvs://cvs.example.org/cvsroot:path/:tag"),
+ "cvs://cvs.example.org/cvsroot:path/:tag")
+ eq(convert("repository:path/:tag"),
+ "repository:path/:tag")
+ eq(convert("repository:/some/path/:tag"),
+ "repository:/some/path/:tag")
+ # not really a URL, but a supported tagless thing
+ eq(convert("local/path/reference.conf"),
+ "local/path/reference.conf")
+
+ def test_load_with_file(self):
+ filename = os.path.abspath(__file__)
+ URL = "file://" + urllib.pathname2url(filename)
+ loader = self.createLoader()
+ # Check that the file isn't copied if we don't ask for a mutable copy:
+ p1 = loader.load(URL)
+ self.assertEqual(p1, filename)
+ # Check that we use the same copy if we ask again:
+ p2 = loader.load(URL)
+ self.assertEqual(p1, p2)
+
+ def test_load_mutable_copy_with_file(self):
+ filename = os.path.abspath(__file__)
+ URL = "file://" + urllib.pathname2url(filename)
+ loader = self.createLoader()
+ # Check that the file isn't copied if we don't ask for a mutable copy:
+ p1 = loader.load(URL)
+ self.assertEqual(p1, filename)
+ # Check that it is copied if we do:
+ p2 = loader.load_mutable_copy(URL)
+ self.assert_(filecmp.cmp(p1, filename, shallow=False))
+ self.assertNotEqual(p1, p2)
+ self.assert_(p2.startswith(tempfile.gettempdir()))
+ # And check that it isn't copied again if we ask again:
+ p3 = loader.load_mutable_copy(URL)
+ self.assertEqual(p2, p3)
+ loader.cleanup()
+
+ def test_load_mutable_copy_with_directory(self):
+ filename = os.path.abspath(__file__)
+ filename = os.path.join(os.path.dirname(filename), "input")
+ self.check_load_mutable_copy_with_directory(filename)
+
+ def test_load_mutable_copy_with_directory_trailing_slash(self):
+ filename = os.path.abspath(__file__)
+ filename = os.path.join(os.path.dirname(filename), "input", "")
+ self.check_load_mutable_copy_with_directory(filename)
+
+ def check_load_mutable_copy_with_directory(self, filename):
+ URL = "file://" + urllib.pathname2url(filename)
+ loader = self.createLoader()
+ # Check that the file isn't copied if we don't ask for a mutable copy:
+ p1 = loader.load(URL)
+ self.assertEqual(p1, filename)
+ # Check that it is copied if we do:
+ common_files = [
+ "packages.map",
+ "README.txt",
+ "collection-1/DEPENDENCIES.cfg",
+ "package/__init__.py",
+ ]
+ # Check that it is copied if we do:
+ p2 = loader.load_mutable_copy(URL)
+ self.assert_(filecmp.cmpfiles(p1, filename, common_files,
+ shallow=False))
+ self.assertNotEqual(p1, p2)
+ self.assert_(p2.startswith(tempfile.gettempdir()))
+ # And check that it isn't copied again if we ask again:
+ p3 = loader.load_mutable_copy(URL)
+ self.assertEqual(p2, p3)
+ loader.cleanup()
+
+
+class FileProxyLoader:
cleanup_called = False
@@ -43,7 +152,7 @@
class FileProxyTestCase(unittest.TestCase):
def setUp(self):
- self.loader = DummyLoader()
+ self.loader = FileProxyLoader()
self.mode = "rU"
self.fp = loader.FileProxy(__file__, self.mode, self.loader)
@@ -87,6 +196,7 @@
def test_suite():
suite = unittest.makeSuite(FileProxyTestCase)
+ suite.addTest(unittest.makeSuite(LoaderTestCase))
return suite
if __name__ == "__main__":
More information about the Zope-CVS
mailing list