Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move tests to root. Fixes #1024 #1277

Merged
merged 2 commits into from
Apr 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/python-distributions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
run: pip install -U gpg
if: "matrix.os != 'windows-latest'"
- name: Run test suite
run: python -m unittest dulwich.tests.test_suite
run: python -m unittest tests.test_suite
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
if: "matrix.os == 'ubuntu-latest'"
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pythontest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,4 @@ jobs:
- name: Coverage test suite run
run: |
pip install --upgrade coverage
python -m coverage run -p -m unittest dulwich.tests.test_suite
python -m coverage run -p -m unittest tests.test_suite
2 changes: 1 addition & 1 deletion .stestr.conf
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
[DEFAULT]
test_path=dulwich/tests
test_path=tests
2 changes: 1 addition & 1 deletion .testr.conf
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[DEFAULT]
test_command=PYTHONPATH=. python -m subunit.run $IDOPTION $LISTOPT dulwich.tests.test_suite
test_command=PYTHONPATH=. python3 -m subunit.run $IDOPTION $LISTOPT tests.test_suite
test_id_option=--load-list $IDFILE
test_list_option=--list
12 changes: 6 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,22 @@ install::
$(SETUP) install --root="$(DESTDIR)"

check:: build
$(RUNTEST) dulwich.tests.test_suite
$(RUNTEST) tests.test_suite

check-tutorial:: build
$(RUNTEST) dulwich.tests.tutorial_test_suite
$(RUNTEST) tests.tutorial_test_suite

check-nocompat:: build
$(RUNTEST) dulwich.tests.nocompat_test_suite
$(RUNTEST) tests.nocompat_test_suite

check-compat:: build
$(RUNTEST) dulwich.tests.compat_test_suite
$(RUNTEST) tests.compat_test_suite

check-pypy:: clean
$(MAKE) check-noextensions PYTHON=pypy

check-noextensions:: clean
$(RUNTEST) dulwich.tests.test_suite
$(RUNTEST) tests.test_suite

check-contrib:: clean
$(RUNTEST) -v dulwich.contrib.test_suite
Expand All @@ -55,7 +55,7 @@ style:
$(RUFF) check .

coverage:
$(COVERAGE) run -m unittest dulwich.tests.test_suite dulwich.contrib.test_suite
$(COVERAGE) run -m unittest tests.test_suite dulwich.contrib.test_suite

coverage-html: coverage
$(COVERAGE) html
Expand Down
2 changes: 2 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
0.21.8 UNRELEASED

* Move tests to root. (Jelmer Vernooij, #1024)

* Convert the optional C implementations to Rust.
(Jelmer Vernooij)

Expand Down
4 changes: 2 additions & 2 deletions dulwich/contrib/README.swift.rst
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ How to start unittest
There is no need to have a Swift cluster running to run the unitests.
Just run the following command in the Dulwich source directory::

$ PYTHONPATH=. python -m dulwich.contrib.test_swift
$ PYTHONPATH=. python -m tests.contrib.test_swift

How to start functional tests
-----------------------------
Expand All @@ -65,7 +65,7 @@ We provide some basic tests to perform smoke tests against a real Swift
cluster. To run those functional tests you need a properly configured
configuration file. The tests can be run as follow::

$ DULWICH_SWIFT_CFG=/etc/swift-dul.conf PYTHONPATH=. python -m dulwich.contrib.test_swift_smoke
$ DULWICH_SWIFT_CFG=/etc/swift-dul.conf PYTHONPATH=. python -m tests.contrib.test_swift_smoke

How to install
--------------
Expand Down
12 changes: 0 additions & 12 deletions dulwich/contrib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,3 @@
# License, Version 2.0.
#


def test_suite():
import unittest

names = [
"paramiko_vendor",
"release_robot",
"swift",
]
module_names = ["dulwich.contrib.test_" + name for name in names]
loader = unittest.TestLoader()
return loader.loadTestsFromNames(module_names)
216 changes: 1 addition & 215 deletions dulwich/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# __init__.py -- The tests for dulwich
# Copyright (C) 2007 James Westby <jw+debian@jameswestby.net>
# Copyright (C) 2024 Jelmer Vernooij <jelmer@jelmer.uk>
#
# Dulwich is dual-licensed under the Apache License, Version 2.0 and the GNU
# General Public License as public by the Free Software Foundation; version 2.0
Expand All @@ -19,217 +19,3 @@
#

"""Tests for Dulwich."""

__all__ = [
"SkipTest",
"TestCase",
"BlackboxTestCase",
"skipIf",
"expectedFailure",
]

import doctest
import os
import shutil
import subprocess
import sys
import tempfile

# If Python itself provides an exception, use that
import unittest
from typing import ClassVar, List
from unittest import SkipTest, expectedFailure, skipIf
from unittest import TestCase as _TestCase


class TestCase(_TestCase):
def setUp(self):
super().setUp()
self.overrideEnv("HOME", "/nonexistent")
self.overrideEnv("GIT_CONFIG_NOSYSTEM", "1")

def overrideEnv(self, name, value):
def restore():
if oldval is not None:
os.environ[name] = oldval
else:
del os.environ[name]

oldval = os.environ.get(name)
if value is not None:
os.environ[name] = value
else:
del os.environ[name]
self.addCleanup(restore)


class BlackboxTestCase(TestCase):
"""Blackbox testing."""

# TODO(jelmer): Include more possible binary paths.
bin_directories: ClassVar[List[str]] = [
os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "..", "bin")),
"/usr/bin",
"/usr/local/bin",
]

def bin_path(self, name):
"""Determine the full path of a binary.

Args:
name: Name of the script
Returns: Full path
"""
for d in self.bin_directories:
p = os.path.join(d, name)
if os.path.isfile(p):
return p
else:
raise SkipTest("Unable to find binary %s" % name)

def run_command(self, name, args):
"""Run a Dulwich command.

Args:
name: Name of the command, as it exists in bin/
args: Arguments to the command
"""
env = dict(os.environ)
env["PYTHONPATH"] = os.pathsep.join(sys.path)

# Since they don't have any extensions, Windows can't recognize
# executablility of the Python files in /bin. Even then, we'd have to
# expect the user to set up file associations for .py files.
#
# Save us from all that headache and call python with the bin script.
argv = [sys.executable, self.bin_path(name), *args]
return subprocess.Popen(
argv,
stdout=subprocess.PIPE,
stdin=subprocess.PIPE,
stderr=subprocess.PIPE,
env=env,
)


def self_test_suite():
names = [
"archive",
"blackbox",
"bundle",
"client",
"config",
"credentials",
"diff_tree",
"fastexport",
"file",
"grafts",
"graph",
"greenthreads",
"hooks",
"ignore",
"index",
"lfs",
"line_ending",
"lru_cache",
"mailmap",
"objects",
"objectspec",
"object_store",
"missing_obj_finder",
"pack",
"patch",
"porcelain",
"protocol",
"reflog",
"refs",
"repository",
"server",
"stash",
"utils",
"walk",
"web",
]
module_names = ["dulwich.tests.test_" + name for name in names]
loader = unittest.TestLoader()
return loader.loadTestsFromNames(module_names)


def tutorial_test_suite():
tutorial = [
"introduction",
"file-format",
"repo",
"object-store",
"remote",
"conclusion",
]
tutorial_files = [f"../../docs/tutorial/{name}.txt" for name in tutorial]

to_restore = []

def overrideEnv(name, value):
oldval = os.environ.get(name)
if value is not None:
os.environ[name] = value
else:
del os.environ[name]
to_restore.append((name, oldval))

def setup(test):
test.__old_cwd = os.getcwd()
test.tempdir = tempfile.mkdtemp()
test.globs.update({"tempdir": test.tempdir})
os.chdir(test.tempdir)
overrideEnv("HOME", "/nonexistent")
overrideEnv("GIT_CONFIG_NOSYSTEM", "1")

def teardown(test):
os.chdir(test.__old_cwd)
shutil.rmtree(test.tempdir)
for name, oldval in to_restore:
if oldval is not None:
os.environ[name] = oldval
else:
del os.environ[name]
to_restore.clear()

return doctest.DocFileSuite(
module_relative=True,
package="dulwich.tests",
setUp=setup,
tearDown=teardown,
*tutorial_files,
)


def nocompat_test_suite():
result = unittest.TestSuite()
result.addTests(self_test_suite())
result.addTests(tutorial_test_suite())
from dulwich.contrib import test_suite as contrib_test_suite

result.addTests(contrib_test_suite())
return result


def compat_test_suite():
result = unittest.TestSuite()
from dulwich.tests.compat import test_suite as compat_test_suite

result.addTests(compat_test_suite())
return result


def test_suite():
result = unittest.TestSuite()
result.addTests(self_test_suite())
if sys.platform != "win32":
result.addTests(tutorial_test_suite())
from dulwich.tests.compat import test_suite as compat_test_suite

result.addTests(compat_test_suite())
from dulwich.contrib import test_suite as contrib_test_suite

result.addTests(contrib_test_suite())
return result
Loading
Loading