# SlapOS software release to test ZODB4-wc2 on Nexedi testing infrastructure.

[buildout]
extends =
# test<X>.cfg configures ZODB.major=<X>.

    ../../stack/nxdtest.cfg
    ../pygolang/buildout.cfg
    buildout.cfg
    ../ZEO/buildout.cfg

parts =
    ZODB
    .nxdtest

#   for instance
    ZODB-python
    slapos-cookbook
    instance.cfg

[ZODB]
major = 4-wc2
[ZODB4-wc2-repository]
revision =
[python]
part = python2.7

# we need persistent to be a git checkout because persistent tests want to
# discover in-tree files that are not present in persistent egg when it is
# installed in non-development mode:
#
#   https://erp5.nexedi.net/test_result_module/20201123-3F859E35/7
#   (look for "AssertionError: could not find my setup.py")
#
#   https://github.com/zopefoundation/persistent/blob/4.6.4-0-g7ed95cf/persistent/tests/test_docs.py#L37-L43
[persistent]
recipe = zc.recipe.egg:develop
setup = ${persistent-repository:location}

[persistent-repository]
recipe  = slapos.recipe.build:gitclone
location = ${buildout:parts-directory}/persistent
repository = https://github.com/zopefoundation/persistent.git
branch = master
revision = 4.6.4-0-g7ed95cf
git-executable = ${git:location}/bin/git

# bin/python is preinstalled with sys.path to ZODB & friends.
[ZODB-python]
<= python-interpreter
eggs +=
  ${ZODB:egg}[test]
  ${ZEO:egg}[test]
  transaction[test]

# env.sh for ZODB's python to be on $PATH.
[ZODB-env.sh]
recipe   = slapos.recipe.template
output = ${buildout:directory}/${:_buildout_section_name_}
inline =
  export PS1="(ZODB-env) $PS1"
  export PATH=${buildout:bin-directory}:$PATH

# .nxdtest to run ZODB tests
[.nxdtest]
<= jinja2-template
inline =
  # determine where ZODB & friends were installed
  from subprocess import check_output
  where = check_output(['python', '-c', """if 1:
        from os.path import dirname
        for m in "ZODB", "persistent", "BTrees", "transaction", "ZEO":
            print(dirname(__import__(m).__file__))
  """],
    universal_newlines=True,
  )
  ZODB, persistent, BTrees, transaction, ZEO = where.split()

  # run tests for whole ZODB stack
  TestCase('ZODB/unit',       ['python', '-m', 'zope.testrunner', '-uv', '--package-path', ZODB, 'ZODB'])
  TestCase('ZODB/functional', ['python', '-m', 'zope.testrunner', '-fv', '--package-path', ZODB, 'ZODB'])

  TestCase('ZEO/unit',       ['python', '-m', 'zope.testrunner', '-uv', '--package-path', ZEO, 'ZEO'])
  TestCase('ZEO/functional', ['python', '-m', 'zope.testrunner', '-fv', '--package-path', ZEO, 'ZEO'])

  TestCase('persistent', ['python', '-m', 'zope.testrunner', '-v', '--package-path', persistent, 'persistent'])
  TestCase('BTrees',     ['python', '-m', 'zope.testrunner', '-v', '--package-path', BTrees, 'BTrees'])

  # transaction uses unittest instead of zope.testrunner
  import os.path
  def P(path): return os.path.join(path, '..')
  TestCase('transaction',['python', '-m', 'unittest', 'discover', '-s', P(transaction)])


# instance to run nxdtest.
[instance.cfg]
<= jinja2-template
inline =
  [buildout]
  extends = ${nxdtest-instance.cfg:output}

  [runTestSuite]
  env.sh  = ${ZODB-env.sh:output}
  workdir = ${buildout:directory}

