Commit 8af74491 authored by Jérome Perrin's avatar Jérome Perrin

README: use regex normalizing to make doctest more readable

https://pypi.org/project/zope.testing/ features "renormalizing" that
this test was already using to make this test independent from actual
paths that can be different but use some paths that looks always the
same (like /sample_buildout/).
Also use this in our patches for shared support so that the test is a
bit more readable and also so that we can assert the actual hash being
used.
parent 54aed005
...@@ -1044,13 +1044,13 @@ process as the recipe tried. ...@@ -1044,13 +1044,13 @@ process as the recipe tried.
... FOO=bar ... FOO=bar
... """ % (shared_dir, src)) ... """ % (shared_dir, src))
>>> print(system(buildout)) #doctest:+ELLIPSIS >>> print(system(buildout)) #doctest:+ELLIPSIS
package: shared directory .../slapos.recipe.cmmi/slapos/recipe/cmmi/shared/package/... set for package package: shared directory /shared/package/FIRST_SHARED_PACKAGE_HASH set for package
Uninstalling package. Uninstalling package.
Installing package. Installing package.
package: Checking whether package is installed at shared path: .../slapos.recipe.cmmi/slapos/recipe/cmmi/shared/package/... package: Checking whether package is installed at shared path: /shared/package/FIRST_SHARED_PACKAGE_HASH
package: [ENV] FOO = bar package: [ENV] FOO = bar
package: Command './configure --prefix=".../slapos.recipe.cmmi/slapos/recipe/cmmi/shared/package/..."' returned non-zero exit status 127 package: Command './configure --prefix="/shared/package/FIRST_SHARED_PACKAGE_HASH"' returned non-zero exit status 127
package: Compilation error. The package is left as is at .../slapos.recipe.cmmi/slapos/recipe/cmmi/shared/package/...__compile__ where you can inspect what went wrong. package: Compilation error. The package is left as is at /shared/package/FIRST_SHARED_PACKAGE_HASH__compile__ where you can inspect what went wrong.
A shell script slapos.recipe.build.env.sh has been generated. You can source it in your shell to reproduce build environment. A shell script slapos.recipe.build.env.sh has been generated. You can source it in your shell to reproduce build environment.
/bin/sh: 1: ./configure: not found /bin/sh: 1: ./configure: not found
While: While:
...@@ -1064,11 +1064,12 @@ process as the recipe tried. ...@@ -1064,11 +1064,12 @@ process as the recipe tried.
If shared-parts is set and shared is True, package will be installed in shared_part/package/a hash of the recipe's configuration options If shared-parts is set and shared is True, package will be installed in shared_part/package/a hash of the recipe's configuration options
>>> _ = system('mv %s/package-0.0.0.tar.gz.bak %s/package-0.0.0.tar.gz' % (src, src)) >>> _ = system('mv %s/package-0.0.0.tar.gz.bak %s/package-0.0.0.tar.gz' % (src, src))
>>> print(system(buildout)) #doctest:+ELLIPSIS >>> print(system(buildout)) #doctest:+ELLIPSIS
package: shared directory .../slapos.recipe.cmmi/slapos/recipe/cmmi/shared/package/... set for package package: shared directory /shared/package/FIRST_SHARED_PACKAGE_HASH set for package
Installing package. Installing package.
package: Checking whether package is installed at shared path: .../slapos.recipe.cmmi/slapos/recipe/cmmi/shared/package/... package: Checking whether package is installed at shared path: /shared/package/FIRST_SHARED_PACKAGE_HASH
package: Removing already existing directory .../slapos.recipe.cmmi/slapos/recipe/cmmi/shared/package/...__compile__ package: [ENV] FOO = bar
configure --prefix=.../slapos.recipe.cmmi/slapos/recipe/cmmi/shared/package/... package: Removing already existing directory /shared/package/FIRST_SHARED_PACKAGE_HASH__compile__
configure --prefix=/shared/package/FIRST_SHARED_PACKAGE_HASH
building package building package
installing package installing package
...@@ -1090,9 +1091,9 @@ Do nothing if one package has been installed. ...@@ -1090,9 +1091,9 @@ Do nothing if one package has been installed.
... FOO=bar ... FOO=bar
... """ % (shared_dir, src)) ... """ % (shared_dir, src))
>>> print(system(buildout)) #doctest:+ELLIPSIS >>> print(system(buildout)) #doctest:+ELLIPSIS
package: shared directory .../slapos.recipe.cmmi/slapos/recipe/cmmi/shared/package/... set for package package: shared directory /shared/package/FIRST_SHARED_PACKAGE_HASH set for package
Installing package. Installing package.
package: Checking whether package is installed at shared path: .../slapos.recipe.cmmi/slapos/recipe/cmmi/shared/package/... package: Checking whether package is installed at shared path: /shared/package/FIRST_SHARED_PACKAGE_HASH
package: This shared package has been installed by other package package: This shared package has been installed by other package
If options change, reinstall in different location: If options change, reinstall in different location:
...@@ -1111,11 +1112,11 @@ If options change, reinstall in different location: ...@@ -1111,11 +1112,11 @@ If options change, reinstall in different location:
... """ % (shared_dir, src)) ... """ % (shared_dir, src))
>>> print(system(buildout)) #doctest:+ELLIPSIS >>> print(system(buildout)) #doctest:+ELLIPSIS
package: shared directory .../slapos.recipe.cmmi/slapos/recipe/cmmi/shared/package/... set for package package: shared directory /shared/package/ANOTHER_SHARED_PACKAGE_HASH set for package
Uninstalling package. Uninstalling package.
Installing package. Installing package.
package: Checking whether package is installed at shared path: .../slapos.recipe.cmmi/slapos/recipe/cmmi/shared/package/... package: Checking whether package is installed at shared path: /shared/package/ANOTHER_SHARED_PACKAGE_HASH
configure --prefix=.../slapos.recipe.cmmi/slapos/recipe/cmmi/shared/package/... configure --prefix=/shared/package/ANOTHER_SHARED_PACKAGE_HASH
building package building package
installing package installing package
......
from slapos.recipe.downloadunpacked import Signature
from zope.testing import renormalizing from zope.testing import renormalizing
import doctest import doctest
import errno import errno
...@@ -319,6 +320,24 @@ class NonInformativeTests(unittest.TestCase): ...@@ -319,6 +320,24 @@ class NonInformativeTests(unittest.TestCase):
self.assertTrue(os.path.exists(build_directory)) self.assertTrue(os.path.exists(build_directory))
def test_suite(): def test_suite():
# Hash used in the test depend on the file:// url of the package, so
# we use re-normalizer to replace SHARED_PACKAGE_HASH with the actual
# hash for this path.
package_url = 'file://%s/package-0.0.0.tar.gz' % os.path.join(
os.path.dirname(__file__), 'testdata')
signature_FIRST_SHARED_PACKAGE_HASH = Signature('.slapos.recipe.cmmi.signature')
signature_FIRST_SHARED_PACKAGE_HASH.update('environment', 'FOO=bar')
signature_FIRST_SHARED_PACKAGE_HASH.update('recipe', 'slapos.recipe.cmmi')
signature_FIRST_SHARED_PACKAGE_HASH.update('shared', 'True')
signature_FIRST_SHARED_PACKAGE_HASH.update('url', package_url)
signature_ANOTHER_SHARED_PACKAGE_HASH = Signature('.slapos.recipe.cmmi.signature')
signature_ANOTHER_SHARED_PACKAGE_HASH.update('change', 'True')
signature_ANOTHER_SHARED_PACKAGE_HASH.update('recipe', 'slapos.recipe.cmmi')
signature_ANOTHER_SHARED_PACKAGE_HASH.update('shared', 'True')
signature_ANOTHER_SHARED_PACKAGE_HASH.update('url', package_url)
suite = unittest.TestSuite(( suite = unittest.TestSuite((
doctest.DocFileSuite( doctest.DocFileSuite(
'README.rst', 'README.rst',
...@@ -326,10 +345,18 @@ def test_suite(): ...@@ -326,10 +345,18 @@ def test_suite():
tearDown=zc.buildout.testing.buildoutTearDown, tearDown=zc.buildout.testing.buildoutTearDown,
optionflags=optionflags, optionflags=optionflags,
checker=renormalizing.RENormalizing([ checker=renormalizing.RENormalizing([
(re.compile('--prefix=\S+sample-buildout'), (re.compile(r'--prefix=\S+sample-buildout'),
'--prefix=/sample_buildout'), '--prefix=/sample_buildout'),
(re.compile('\s/\S+sample-buildout'), (re.compile(r'\s/\S+sample-buildout'),
' /sample_buildout'), ' /sample_buildout'),
(re.compile(r'--prefix=\S+\/shared\/'),
'--prefix=/shared/'),
(re.compile(r'\s/\S+\/shared\/'),
' /shared/'),
(re.compile('FIRST_SHARED_PACKAGE_HASH'),
signature_FIRST_SHARED_PACKAGE_HASH.hexdigest()),
(re.compile('ANOTHER_SHARED_PACKAGE_HASH'),
signature_ANOTHER_SHARED_PACKAGE_HASH.hexdigest()),
zc.buildout.testing.normalize_path, zc.buildout.testing.normalize_path,
zc.buildout.testing.not_found, zc.buildout.testing.not_found,
]), ]),
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment