[Zope-CVS] CVS: Packages/zpkgtools/zpkgtools/tests - .cvsignore:1.1
ignorethis.txt:1.1 somescript.py:1.1 test_cvsloader.py:1.1
test_dependencies.py:1.1 test_include.py:1.1
Fred L. Drake, Jr.
fred at zope.com
Fri Mar 5 16:39:24 EST 2004
Update of /cvs-repository/Packages/zpkgtools/zpkgtools/tests
In directory cvs.zope.org:/tmp/cvs-serv10053/zpkgtools/tests
Added Files:
.cvsignore ignorethis.txt somescript.py test_cvsloader.py
test_dependencies.py test_include.py
Log Message:
first steps for the release assembler
=== Added File Packages/zpkgtools/zpkgtools/tests/.cvsignore ===
just-ignore-this
=== Added File Packages/zpkgtools/zpkgtools/tests/ignorethis.txt ===
Sample file needed to test that a file can be ignored.
=== Added File Packages/zpkgtools/zpkgtools/tests/somescript.py ===
#! /usr/bin/env python
"""This is a script used to test permission copying."""
print "You though this would do something useful? Sheesh!"
=== Added File Packages/zpkgtools/zpkgtools/tests/test_cvsloader.py ===
##############################################################################
#
# Copyright (c) 2004 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""Tests of zpkgtools.cvsloader."""
import os.path
import shutil
import tempfile
import unittest
from StringIO import StringIO
from zpkgtools import cvsloader
class UrlUtilitiesTestCase(unittest.TestCase):
def test_getCvsRoot(self):
def check(cvsroot, *args, **kw):
kw["path"] = "foo/bar"
kw["password"] = "passwd"
kw["tag"] = "TAG" # should not show up in CVSROOT setting
cvsurl = cvsloader.CvsUrl(*args, **kw)
self.assertEqual(cvsurl.getCvsRoot(), cvsroot)
check("/usr/local/cvsroot",
None, None, "/usr/local/cvsroot")
check(":ext:cvs.example.org:/cvsroot",
"ext", "cvs.example.org", "/cvsroot")
check(":ext:myuser at cvs.example.org:/cvsroot",
"ext", "cvs.example.org", "/cvsroot", username="myuser")
check(":pserver:cvs.example.org:/cvsroot",
"pserver", "cvs.example.org", "/cvsroot")
def test_cvs_getUrl(self):
cvsurl = cvsloader.CvsUrl("", "cvs.example.org", "/cvsroot",
"project/module")
self.assertEqual(cvsurl.getUrl(),
"cvs://cvs.example.org/cvsroot:project/module")
cvsurl.path = "module"
cvsurl.tag = "TAG"
self.assertEqual(cvsurl.getUrl(),
"cvs://cvs.example.org/cvsroot:module:TAG")
cvsurl.username = "myuser"
self.assertEqual(cvsurl.getUrl(),
"cvs://myuser@cvs.example.org/cvsroot:module:TAG")
cvsurl.password = "pw"
self.assertEqual(cvsurl.getUrl(),
"cvs://myuser:pw@cvs.example.org/cvsroot:module:TAG")
def test_repository_getUrl(self):
repo = cvsloader.RepositoryUrl("/absolute/path")
self.assertEqual(repo.getUrl(), "repository:/absolute/path")
repo.tag = "TAG"
self.assertEqual(repo.getUrl(), "repository:/absolute/path:TAG")
def test_repository_join_absolute_path(self):
repo = cvsloader.RepositoryUrl("/absolute/path")
cvsurl = cvsloader.CvsUrl("", "cvs.example.org", "/cvsroot",
"project/module")
result = repo.join(cvsurl)
self.assert_(not result.type)
self.assertEqual(result.host, "cvs.example.org")
self.assertEqual(result.cvsroot, "/cvsroot")
self.assertEqual(result.path, "absolute/path")
self.assert_(not result.tag)
cvsurl.tag = "TAG"
result = repo.join(cvsurl)
self.assert_(not result.type)
self.assertEqual(result.host, "cvs.example.org")
self.assertEqual(result.cvsroot, "/cvsroot")
self.assertEqual(result.path, "absolute/path")
self.assertEqual(result.tag, "TAG")
repo.tag = "FOO"
result = repo.join(cvsurl)
self.assertEqual(result.path, "absolute/path")
self.assertEqual(result.tag, "FOO")
cvsurl.tag = None
result = repo.join(cvsurl)
self.assertEqual(result.path, "absolute/path")
self.assertEqual(result.tag, "FOO")
def test_repository_join_relative_path(self):
repo = cvsloader.RepositoryUrl("relative/path")
cvsurl = cvsloader.CvsUrl("", "cvs.example.org", "/cvsroot",
"project/module")
result = repo.join(cvsurl)
self.assert_(not result.type)
self.assertEqual(result.host, "cvs.example.org")
self.assertEqual(result.cvsroot, "/cvsroot")
self.assertEqual(result.path, "project/module/relative/path")
self.assert_(not result.tag)
cvsurl.tag = "TAG"
result = repo.join(cvsurl)
self.assert_(not result.type)
self.assertEqual(result.host, "cvs.example.org")
self.assertEqual(result.cvsroot, "/cvsroot")
self.assertEqual(result.path, "project/module/relative/path")
self.assertEqual(result.tag, "TAG")
repo.tag = "FOO"
result = repo.join(cvsurl)
self.assertEqual(result.path, "project/module/relative/path")
self.assertEqual(result.tag, "FOO")
cvsurl.tag = None
result = repo.join(cvsurl)
self.assertEqual(result.path, "project/module/relative/path")
self.assertEqual(result.tag, "FOO")
def test_parse_cvs(self):
def check(url,
type, username, password, host, cvsroot, path, tag):
cvsurl = cvsloader.parse(url)
self.assert_(isinstance(cvsurl, cvsloader.CvsUrl))
self.assertEqual(cvsurl.type, type)
self.assertEqual(cvsurl.username, username)
self.assertEqual(cvsurl.password, password)
self.assertEqual(cvsurl.host, host)
self.assertEqual(cvsurl.cvsroot, cvsroot)
self.assertEqual(cvsurl.path, path)
self.assertEqual(cvsurl.tag, tag)
check("cvs://cvs.example.org:pserver/cvsroot:module/file.txt",
"pserver", None, None, "cvs.example.org", "/cvsroot",
"module/file.txt", None)
check("CVS://user:pw@cvs.example.org:pserver/cvsroot/path:module/:TAG",
"pserver", "user", "pw", "cvs.example.org", "/cvsroot/path",
"module/", "TAG")
# An empty path is ok; it means the same as "." (the whole repository)
check("cvs://cvs.example.org:ext/cvsroot:",
"ext", None, None, "cvs.example.org", "/cvsroot",
"", None)
# Empty username, password, type, and tag must be normalized to None:
check("cvs://cvs.example.org/cvsroot:path:",
None, None, None, "cvs.example.org", "/cvsroot",
"path", None)
# Local filesystem access to repository:
check("cvs:///cvsroot:module/path/file.txt:TAG",
None, None, None, None, "/cvsroot",
"module/path/file.txt", "TAG")
# Path within repository not specified; means the whole repository
check("cvs://cvs.example.org:ext/cvsroot",
"ext", None, None, "cvs.example.org", "/cvsroot",
None, None)
# Too many parts:
self.assertRaises(ValueError,
cvsloader.parse,
"cvs://hostname/cvsroot:path:TAG:junk")
# Can't generate a proper CVSROOT value:
self.assertRaises(ValueError,
cvsloader.parse, "cvs://")
def test_parse_repository(self):
def check(url, path, tag):
cvsurl = cvsloader.parse(url)
self.assert_(isinstance(cvsurl, cvsloader.RepositoryUrl))
self.assertEqual(cvsurl.path, path)
self.assertEqual(cvsurl.tag, tag)
check("repository:path/to/some/file.txt",
"path/to/some/file.txt", None)
check("repository:/some/path/",
"/some/path/", None)
check("repository:path/to/some/file.txt:TAG",
"path/to/some/file.txt", "TAG")
check("repository:/some/path/:TAG",
"/some/path/", "TAG")
check("repository::TAG",
None, "TAG")
check("repository::",
None, None)
check("repository:",
None, None)
# Too many parts:
self.assertRaises(ValueError,
cvsloader.parse, "repository:path:TAG:junk")
def test_parse_invalid(self):
# Scheme isn't "cvs" or "repository":
self.assertRaises(ValueError,
cvsloader.parse, "http://www.example.org/")
class CvsWorkingDirectoryTestCase(unittest.TestCase):
def setUp(self):
self.destination = tempfile.mkdtemp(prefix="test_cvsloader_")
self.cvsdir = os.path.join(self.destination, "CVS")
os.mkdir(self.cvsdir)
self.filename = os.path.join(self.destination, "file.txt")
f = open(self.filename, "w")
f.close()
def tearDown(self):
shutil.rmtree(self.destination)
def check(self, filename,
type, username, password, host, cvsroot, path, tag):
cvsurl = cvsloader.fromPath(filename)
self.assertEqual(cvsurl.type, type)
self.assertEqual(cvsurl.username, username)
self.assertEqual(cvsurl.password, password)
self.assertEqual(cvsurl.host, host)
self.assertEqual(cvsurl.cvsroot, cvsroot)
self.assertEqual(cvsurl.path, path)
self.assertEqual(cvsurl.tag, tag)
def initialize(self, root, repository, tag=None):
self.writeCvsFile("Root", root + "\n")
self.writeCvsFile("Repository", repository + "\n")
if tag:
self.writeCvsFile("Tag", "T%s\n" % tag)
def writeCvsFile(self, name, content):
f = open(os.path.join(self.cvsdir, name), "w")
f.write(content)
f.close()
# tests
def test_without_tag(self):
self.initialize(":ext:cvs.example.org:/cvsroot",
"module/package")
# Check the directory itself:
self.check(self.destination,
"ext", None, None, "cvs.example.org", "/cvsroot",
"module/package/", None)
# And for a contained file:
self.check(self.filename,
"ext", None, None, "cvs.example.org", "/cvsroot",
"module/package/file.txt", None)
def test_with_tag(self):
self.initialize(":ext:cvs.example.org:/cvsroot",
"module/package",
"TAG")
# Check the directory itself:
self.check(self.destination,
"ext", None, None, "cvs.example.org", "/cvsroot",
"module/package/", "TAG")
# And for a contained file:
self.check(self.filename,
"ext", None, None, "cvs.example.org", "/cvsroot",
"module/package/file.txt", "TAG")
def test_without_username(self):
self.initialize(":ext:myuser at cvs.example.org:/cvsroot",
"module/package")
self.check(self.destination,
"ext", "myuser", None, "cvs.example.org", "/cvsroot",
"module/package/", None)
def test_with_entries_override(self):
self.initialize(":ext:cvs.example.org:/cvsroot",
"module/package")
self.writeCvsFile(
"Entries",
"/file.txt/1.2.2.8/Mon Mar 1 23:00:24 2004/-kk/Tnew-tag\n")
self.check(self.filename,
"ext", None, None, "cvs.example.org", "/cvsroot",
"module/package/file.txt", "new-tag")
def test_with_entries_tag(self):
self.initialize(":ext:cvs.example.org:/cvsroot",
"module/package",
"TAG")
self.writeCvsFile(
"Entries",
"/file.txt/1.2.2.8/Mon Mar 1 23:00:24 2004/-kk/Tnew-tag\n")
self.check(self.filename,
"ext", None, None, "cvs.example.org", "/cvsroot",
"module/package/file.txt", "new-tag")
class CvsLoaderTestCase(unittest.TestCase):
"""Tests for the CVS loader itself.
These tests verify that the runCvsExport() method is called with
the expected information, not that runCvsExport() is actually
doing to right thing. This does not assume that any CVS
repositories are actually available.
"""
cvs_return_code = 0
rlog_output = ""
def runCvsExport(self, cvsroot, workdir, tag, path):
self.assert_(os.path.isdir(workdir),
"working directory must exist and be a directory")
self.cvsroot = cvsroot
self.workdir = workdir
self.tag = tag
self.path = path
return self.cvs_return_code
def openCvsRLog(self, cvsroot, path):
# XXX This assumes that os.popen() is used to get CVS output,
# but ensures that the generation of the command string
# doesn't fail in simple ways.
self.rlog_cvsroot = cvsroot
self.rlog_path = path
os_popen = os.popen
os.popen = self.popen
try:
return self.loader.__class__.openCvsRLog(
self.loader, cvsroot, path)
finally:
os.popen = os_popen
def popen(self, command, mode="r"):
self.rlog_command = command
return StringIO(self.rlog_output)
def createLoader(self, baseurl):
"""Create a loader that won't actually access CVS."""
loader = cvsloader.CvsLoader(baseurl)
self.loader = loader
loader.runCvsExport = self.runCvsExport
loader.openCvsRLog = self.openCvsRLog
return loader
# tests
def test_simple_load_ok(self):
self.rlog_output = "/cvsroot/module/dir/README.txt,v\n"
baseurl = cvsloader.parse(
"cvs://cvs.example.org:ext/cvsroot:module/dir")
loader = self.createLoader(baseurl)
path = loader.load("repository:")
self.assertEqual(self.cvsroot, ":ext:cvs.example.org:/cvsroot")
self.assertEqual(self.tag, "HEAD")
self.assertEqual(self.path, "module/dir")
self.assert_(os.path.isdir(self.workdir),
"working directory must exist after a successful run")
self.assertEqual(self.rlog_cvsroot, self.cvsroot)
self.assertEqual(self.rlog_path, self.path)
def test_simple_load_error(self):
self.cvs_return_code = 1
url = "cvs://cvs.example.org:ext/cvsroot:module/dir"
baseurl = cvsloader.parse(url)
loader = self.createLoader(baseurl)
try:
loader.load("repository:")
except cvsloader.CvsLoadingError, e:
self.assertEqual(e.exitcode, self.cvs_return_code)
self.assertEqual(e.cvsurl.getUrl(), url)
else:
self.fail("expected CvsLoadingError")
self.assertEqual(self.cvsroot, ":ext:cvs.example.org:/cvsroot")
self.assertEqual(self.tag, "HEAD")
self.assertEqual(self.path, "module/dir")
self.assert_(not os.path.exists(self.workdir),
"working directory must not exist after a failed run")
def test_isFileResource_file(self):
self.check_isFileResource("/cvsroot/module/FOO,v\n",
True)
def test_isFileResource_file_in_attic(self):
self.check_isFileResource("/cvsroot/module/Attic/FOO,v\n",
True)
def test_isFileResource_directory(self):
self.check_isFileResource("/cvsroot/module/FOO/FILE.txt,v\n"
"/cvsroot/module/FOO/README.txt,v\n",
False)
def check_isFileResource(self, rlog_output, expected_result):
self.rlog_output = rlog_output
baseurl = cvsloader.parse(
"cvs://user@cvs.example.org:pserver/cvsroot:module")
loader = self.createLoader(baseurl)
repourl = cvsloader.parse("repository:FOO:TAG")
self.assertEqual(not not loader.isFileResource(repourl),
expected_result)
self.assertEqual(self.rlog_path, "module/FOO")
self.assertEqual(self.rlog_cvsroot,
":pserver:user at cvs.example.org:/cvsroot")
def test_suite():
suite = unittest.makeSuite(UrlUtilitiesTestCase)
suite.addTest(unittest.makeSuite(CvsWorkingDirectoryTestCase))
suite.addTest(unittest.makeSuite(CvsLoaderTestCase))
return suite
if __name__ == "__main__":
unittest.main(defaultTest="test_suite")
=== Added File Packages/zpkgtools/zpkgtools/tests/test_dependencies.py ===
##############################################################################
#
# Copyright (c) 2004 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""Tests for zpkgtools.dependencies."""
import unittest
from StringIO import StringIO
from zpkgtools import dependencies
class DependenciesTestCase(unittest.TestCase):
def test_empty_file(self):
sio = StringIO("")
deps = dependencies.load(sio)
self.assert_(not deps.modules)
self.assert_(not deps.others)
def test_empty_file_with_comments(self):
sio = StringIO("""\
# This is a comment.
# So is this.
""")
deps = dependencies.load(sio)
self.assert_(not deps.modules)
self.assert_(not deps.others)
def test_just_modules(self):
sio = StringIO("""\
zope.foo
zope.app.bar
""")
deps = dependencies.load(sio)
self.assertEqual(len(deps.modules), 2)
self.assert_("zope.foo" in deps.modules)
self.assert_("zope.app.bar" in deps.modules)
self.assert_(not deps.others)
def test_just_others(self):
sio = StringIO("""\
not-a-module
feature:zope.bar
""")
deps = dependencies.load(sio)
self.assert_(not deps.modules)
self.assertEqual(len(deps.others), 2)
self.assert_("not-a-module" in deps.others)
self.assert_("feature:zope.bar" in deps.others)
def test_modules_and_others(self):
sio = StringIO("""\
not-a-module
zope.foo
# Comments can go here
zope.app.bar
feature:zope.bar
""")
deps = dependencies.load(sio)
self.assertEqual(len(deps.modules), 2)
self.assert_("zope.foo" in deps.modules)
self.assert_("zope.app.bar" in deps.modules)
self.assertEqual(len(deps.others), 2)
self.assert_("not-a-module" in deps.others)
self.assert_("feature:zope.bar" in deps.others)
def test_blank_line_ends_data(self):
sio = StringIO("""\
zope.app
zope.schema
feature:foo
feature:but-not-really
zope.yeahright
""")
deps = dependencies.load(sio)
self.assertEqual(len(deps.modules), 2)
self.assertEqual(len(deps.others), 1)
self.assert_("feature:but-not-really" not in deps.modules)
self.assert_("feature:but-not-really" not in deps.others)
self.assert_("zope.yeahright" not in deps.modules)
self.assert_("zope.yeahright" not in deps.others)
def test_suite():
return unittest.makeSuite(DependenciesTestCase)
if __name__ == "__main__":
unittest.main(defaultTest="test_suite")
=== Added File Packages/zpkgtools/zpkgtools/tests/test_include.py ===
##############################################################################
#
# Copyright (c) 2004 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""Tests for the inclusion processor."""
import filecmp
import os
import shutil
import tempfile
import unittest
import urllib2
from os.path import join
from StringIO import StringIO
from zpkgtools import cvsloader
from zpkgtools import include
class InclusionProcessorTestCase(unittest.TestCase):
def setUp(self):
self.source = os.path.dirname(__file__)
self.destination = tempfile.mkdtemp(prefix="test_include_")
self.processor = include.InclusionProcessor(self.source,
self.destination)
self.source = os.path.abspath(self.source)
def tearDown(self):
shutil.rmtree(self.destination)
def test_simple_includespec(self):
f = StringIO("""
# This is a comment. It should be ignored.
foo.html http://www.python.org/index.html
doc/whatzit.txt repository:doc/whatzit.txt
ignorethis.txt -
# Another comment.
""")
self.processor.loadSpecification(f, "<string>")
self.assertEqual(len(self.processor.excludes), 1)
self.assertEqual(len(self.processor.includes), 2)
self.assert_(join(self.source, "ignorethis.txt")
in self.processor.excludes)
self.assertEqual(self.processor.includes["foo.html"],
"http://www.python.org/index.html")
self.assertEqual(self.processor.includes[join("doc", "whatzit.txt")],
"repository:doc/whatzit.txt")
def test_error_on_nonexistant_ignore(self):
f = StringIO("""
does-not-exist.txt -
""")
try:
self.processor.loadSpecification(f, "<string>")
except include.InclusionSpecificationError, e:
self.assertEqual(e.filename, "<string>")
self.assertEqual(e.lineno, 2)
else:
self.fail("expected InclusionSpecificationError")
def test_error_on_omitted_source(self):
f = StringIO("whatzit.txt \n")
try:
self.processor.loadSpecification(f, "<string>")
except include.InclusionSpecificationError, e:
self.assertEqual(e.filename, "<string>")
self.assertEqual(e.lineno, 1)
else:
self.fail("expected InclusionSpecificationError")
def test_globbing_on_ignore(self):
f = StringIO("*.txt -")
self.processor.loadSpecification(f, "<string>")
self.assertEqual(len(self.processor.excludes), 1)
self.assert_(join(self.source, "ignorethis.txt")
in self.processor.excludes)
def test_normalizePath(self):
normalize = self.processor.normalizePath
self.check_normalize_paths(normalize)
def test_normalizePathOrURL(self):
normalize = self.processor.normalizePathOrURL
self.check_normalize_paths(normalize)
self.check_normalize_urls(normalize)
def check_normalize_paths(self, normalize):
INCLUDES = "INCLUDES.txt"
self.assertEqual(normalize("README.txt", "t", INCLUDES, 1),
"README.txt")
self.assertEqual(normalize("doc/README.txt", "t", INCLUDES, 2),
join("doc", "README.txt"))
# Ignore this because it looks like a Windows drive letter:
self.assertRaises(include.InclusionSpecificationError,
normalize, "c:foo/bar", "t", INCLUDES, 3)
# Absolute paths are an error as well:
self.assertRaises(include.InclusionSpecificationError,
normalize, "/absolute/path", "t", INCLUDES, 4)
# Relative paths that point up the hierarchy are also disallowed:
self.assertRaises(include.InclusionSpecificationError,
normalize, "abc/../../def.txt", "t", INCLUDES, 5)
self.assertRaises(include.InclusionSpecificationError,
normalize, "../def.txt", "t", INCLUDES, 6)
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", INCLUDES, 1), url)
def test_createDistributionTree_creates_destination(self):
os.rmdir(self.destination)
self.processor.createDistributionTree()
self.assert_(os.path.isdir(self.destination))
self.assert_(os.path.isfile(join(self.destination, "ignorethis.txt")))
def test_createDistributionTree(self):
sio = StringIO("__init__.py -")
self.processor.loadSpecification(sio, "<string>")
self.processor.createDistributionTree()
self.check_file("ignorethis.txt")
self.check_file("somescript.py")
self.assert_(not os.path.exists(join(self.destination, "__init__.py")))
self.assert_(not os.path.exists(join(self.destination, "CVS")))
self.assert_(not os.path.exists(join(self.destination, ".cvsignore")))
def check_file(self, name):
srcname = join(self.source, name)
destname = join(self.destination, name)
self.assert_(os.path.isfile(destname))
srcstat = os.stat(srcname)
deststat = os.stat(destname)
self.assertEqual(srcstat.st_mode, deststat.st_mode)
self.assertEqual(srcstat.st_mtime, deststat.st_mtime)
self.assertEqual(srcstat.st_atime, deststat.st_atime)
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")
cvsurl, destination = self.args
self.assertEqual(cvsurl.getUrl(),
"cvs://cvs.zope.org:pserver/cvs-repository:Zope3")
self.assertEqual(destination,
os.path.join(self.destination, "somedir"))
def test_including_from_cvs_url_without_base(self):
self.start_including_from_cvs_url()
self.processor.cvsurl = None
self.processor.addSingleInclude(
"somedir",
"cvs://cvs.zope.org:pserver/cvs-repository:Zope3")
cvsurl, destination = self.args
self.assertEqual(cvsurl.getUrl(),
"cvs://cvs.zope.org:pserver/cvs-repository:Zope3")
self.assertEqual(destination,
os.path.join(self.destination, "somedir"))
def test_including_from_repository_url(self):
self.start_including_from_cvs_url()
self.processor.addSingleInclude("somedir", "repository:somedir:TAG")
cvsurl, destination = self.args
self.assertEqual(cvsurl.getUrl(), "repository:somedir:TAG")
self.assertEqual(destination,
os.path.join(self.destination, "somedir"))
def start_including_from_cvs_url(self):
self.processor.cvsurl = cvsloader.parse(
"cvs://cvs.example.org:ext/foo:module/dir/:TAG")
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
def save_args(self, *args):
self.args = args
def test_including_from_repository_url_without_base(self):
# When using a repository: URL, there must be a base cvs: URL
# for the InclusionProcessor.
self.processor.cvsurl = None
self.assertRaises(include.InclusionError,
self.processor.addSingleInclude,
"somedir", "repository:somedir:TAG")
def test_including_from_url(self):
URL = "http://www.example.org/"
old_urlopen = urllib2.urlopen
self.called = False
def my_urlopen(url):
self.assertEqual(url, URL)
self.called = True
return StringIO("my_urlopen_data\n")
urllib2.urlopen = my_urlopen
try:
self.processor.addSingleInclude("somefile.txt", URL)
finally:
urllib2.urlopen = old_urlopen
self.assert_(self.called)
resultfile = os.path.join(self.destination, "somefile.txt")
self.assert_(os.path.isfile(resultfile))
f = open(resultfile, "rU")
text = f.read()
f.close()
self.assertEqual(text, "my_urlopen_data\n")
def test_including_from_file(self):
# 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)
sourcefile = os.path.join(self.source, FILENAME)
resultfile = os.path.join(self.destination, "foo", "splat.txt")
self.assert_(os.path.isfile(resultfile))
self.assert_(filecmp.cmp(resultfile, sourcefile, shallow=False))
def test_suite():
return unittest.makeSuite(InclusionProcessorTestCase)
if __name__ == "__main__":
unittest.main(defaultTest="test_suite")
More information about the Zope-CVS
mailing list