view test/test_instance.py @ 7827:604da0650797

test: add basic tests using hypothesis It is segregated to its own file. I am skipping the entire file using importorskip(). Mixing hypothesis tests with non-hypothesis tests is tricky. Hypothesis uses decorators before test commands: @given(text()) @settings(max_examples=_max_examples) Pytest runs the decorators and the arguments as part of scanning the file for tests. This means the decorator (given, settings ...) and the strategies inside the decorators (e.g. text()) have to be defined using a lambda or something. Only aborting at the top of the file using importorskip prevents having to define all the symbols that would be imported from hypothesis.
author John Rouillard <rouilj@ieee.org>
date Sun, 24 Mar 2024 13:49:52 -0400
parents 778a9f455067
children 9c3ec0a5c7fc
line wrap: on
line source

#
# Copyright (C) 2020 John Rouillard
# All rights reserved.
# For license terms see the file COPYING.txt.
#

from __future__ import print_function
import unittest, os, shutil, errno, sys, difflib

from roundup import instance
from roundup.instance import TrackerError

try:
  # python2
  import pathlib2 as pathlib
except ImportError:
  # python3
  import pathlib

from . import db_test_base

class InstanceTest(unittest.TestCase):

    backend = 'anydbm'

    def setUp(self):
        self.dirname = '_test_instance'
        # set up and open a tracker
        self.instance = db_test_base.setupTracker(self.dirname, self.backend)

        # open the database
        self.db = self.instance.open('admin')

        self.db.commit()
        self.db.close()

    def tearDown(self):
        if self.db:
            self.db.close()
        try:
            shutil.rmtree(self.dirname)
        except OSError as error:
            if error.errno not in (errno.ENOENT, errno.ESRCH): raise


    def testOpenOldStyle(self):
        pathlib.Path(os.path.join(self.dirname, "dbinit.py")).touch()
        # no longer support old style tracker configs
        self.assertRaises(TrackerError, instance.open, self.dirname)


Roundup Issue Tracker: http://roundup-tracker.org/