How to use testfixtures - 10 common examples

To help you get started, we’ve selected a few testfixtures examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Yelp / pgctl / tests / unit / cli.py View on Github external
def test_nonsense(in_example_dir):
    with ShouldRaise(SystemExit(2)):
        main(['nonsense'])
github byceps / byceps / tests / services / shop / base.py View on Github external
def create_article(self, shop_id, **kwargs):
        article = create_article(shop_id, **kwargs)

        self.db.session.add(article)
        self.db.session.commit()

        return article
github tarmstrong / nbdiff / tests / test_hg_adapter.py View on Github external
    @tempdir()
    def test_get_modified_notebooks_empty(self, d):
        os.chdir(os.path.join(d.path))
        hglib.init()
        adapter = HgAdapter()
        result = adapter.get_modified_notebooks()
        self.assertTrue(result == [])
github tarmstrong / nbdiff / tests / test_hg_adapter.py View on Github external
    @tempdir()
    def test_get_modified_notebooks(self, d):
        os.chdir(d.path)
        client = hglib.init()
        client.open()
        d.makedir('first')
        d.makedir('first/second')
        path = d.write('first/second/1.ipynb', 'initial')
        self.assertEqual(d.read('first/second/1.ipynb'), 'initial')
        client.add('first/second/1.ipynb')
        client.commit("message")
        file = open(path, 'w')
        file.write("modified")
        file.close()
        self.assertEqual(d.read('first/second/1.ipynb'), 'modified')
        os.chdir(os.path.join(d.path, 'first'))
github tarmstrong / nbdiff / tests / test_hg_adapter.py View on Github external
    @tempdir()
    def test_get_unmerged_notebooks_empty(self, d):
        os.chdir(os.path.join(d.path))
        hglib.init()
        adapter = HgAdapter()
        result = adapter.get_unmerged_notebooks()
        self.assertTrue(result == [])
github bcb / jsonrpcclient / tests / test_client.py View on Github external
def test(self):
        with LogCapture() as capture:
            DummyClient().log_response(
                Response('{"jsonrpc": "2.0", "result": 5, "id": 1}')
            )
        capture.check(
            (
                "jsonrpcclient.client.response",
                "INFO",
                StringComparison(r'.*"result": 5.*'),
            )
github Yelp / pgctl / tests / spec / examples.py View on Github external
if limit > 0:
                        import time
                        time.sleep(wait)
                        limit -= wait
                        continue
                    else:
                        break
                else:
                    raise
            buf += block

        from testfixtures import StringComparison as S
        buf = norm.pgctl(buf.decode('UTF-8'))
        print('NORMED:')
        print(buf)
        assert buf == S('''(?s)\
==> playground/ohhi/logs/current <==
{TIMESTAMP} [oe].*
==> playground/sweet/logs/current <==
{TIMESTAMP} sweet
{TIMESTAMP} sweet_error

==> playground/ohhi/logs/current <==
.*{TIMESTAMP} .*$''')
        assert p.poll() is None  # it's still running

        p.terminate()

        assert p.wait() == -15
github bcb / jsonrpcclient / tests / test_client.py View on Github external
def test(self, *_):
        with LogCapture() as capture:
            DummyClient().log_request('{"jsonrpc": "2.0", "method": "foo"}')
        capture.check(
            (
                "jsonrpcclient.client.request",
                "INFO",
                StringComparison(r'.*"method": "foo".*'),
            )
github byceps / byceps / tests / helpers.py View on Github external
def create_user_with_detail(*args, **kwargs):
    user = _create_user_with_detail(*args, **kwargs)

    db.session.add(user)
    try:
        db.session.commit()
    except Exception as e:
        db.session.rollback()
        raise UserCreationFailed(e)

    return user
github guyzmo / git-repo / tests / helpers.py View on Github external
def setup_git_popen(self):
        # repository mockup (in a temporary place)
        self.repository = Repo.init(self.tempdir.name)
        # setup git command mockup
        self.Popen = MockPopen()
        def FixPopen(*a, **k):
            if 'start_new_session' in k:
                del k['start_new_session']
            return self.Popen.Popen(*a, **k)
        self.Popen.mock.Popen.side_effect = FixPopen
        self.Popen.mock.Popen_instance.stdin = None
        self.Popen.mock.Popen_instance.wait = lambda *a, **k: self.Popen.wait()
        self.Popen.mock.Popen_instance.__enter__ = lambda self: self
        self.Popen.mock.Popen_instance.__exit__ = lambda self, *a, **k: None