Skip to content
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
8 changes: 3 additions & 5 deletions .github/workflows/alpine-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,13 @@ jobs:

- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
fetch-depth: 0
persist-credentials: false

- name: Set workspace ownership
run: |
chown -R runner:docker -- "$GITHUB_WORKSPACE"
shell: sh -exo pipefail {0} # Run this as root, not the "runner" user.

- name: Prepare this repo for tests
run: |
./init-tests-after-clone.sh

- name: Set git user identity and command aliases for the tests
run: |
git config --global user.email "travis@ci.com"
Expand Down Expand Up @@ -95,6 +90,9 @@ jobs:
python --version
python -c 'import os, sys; print(f"{sys.platform=}, {os.name=}")'

- name: Remove source Git metadata to verify fixture isolation
run: .venv/bin/python -c "from pathlib import Path; from git.util import rmtree; rmtree('.git'); assert not Path('.git').exists()"

- name: Test with pytest
run: |
. .venv/bin/activate
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/backend-benchmark.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ jobs:
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
fetch-depth: 0
persist-credentials: false
- uses: actions/setup-python@6d4fd22b20465ccc0f7354476588e8df7c9ca0e0 # v7.1.0
with:
Expand Down Expand Up @@ -50,7 +49,8 @@ jobs:
.bench-gix/bin/python -m pip install '.[gix]' -r test/performance/benchmark-requirements.txt
- name: Prepare the shared read-only benchmark fixture
run: |
.bench-cli/bin/python -c 'from pathlib import Path; from gix import testtools; print("BENCH_REPO=" + str((testtools.scripted_fixture_read_only_with_args("benchmark.sh", [str(Path.cwd())]) / "repo").resolve()))' >> "$GITHUB_ENV"
rm -rf .git
.bench-cli/bin/python -c 'from gix import testtools; print("BENCH_REPO=" + str((testtools.scripted_fixture_read_only_with_args("benchmark.sh", []) / "repo").resolve()))' >> "$GITHUB_ENV"
mkdir benchmark-results
- name: Measure GixPython operations, opening and discovery first
env:
Expand Down
5 changes: 0 additions & 5 deletions .github/workflows/cygwin-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ jobs:

- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
fetch-depth: 0
persist-credentials: false

- name: Install Cygwin
Expand Down Expand Up @@ -61,10 +60,6 @@ jobs:
git config --global --add safe.directory "$(pwd)/.git"
git config --global core.autocrlf false

- name: Prepare this repo for tests
run: |
./init-tests-after-clone.sh

- name: Set git user identity and command aliases for the tests
run: |
git config --global user.email "travis@ci.com"
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/dependencies.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ jobs:
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
fetch-depth: 0
persist-credentials: false
- uses: actions/setup-python@6d4fd22b20465ccc0f7354476588e8df7c9ca0e0 # v7.1.0
with:
Expand All @@ -45,8 +44,9 @@ jobs:
run: flake8 "$PROJECT/$PROJECT" --count --select=E9,F63,F7,F82 --show-source --statistics
- name: Test
run: |
rm -rf .git
if test "$PROJECT" = gitdb; then
GITDB_TEST_GIT_REPO_BASE="$(git rev-parse --git-common-dir)" pytest -o addopts= -v gitdb/gitdb/test
pytest -o addopts= -v gitdb/gitdb/test
else
pytest -o addopts= -v smmap/smmap/test
fi
Expand Down
8 changes: 3 additions & 5 deletions .github/workflows/pythonpackage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ jobs:
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
fetch-depth: 0
persist-credentials: false

- name: Set up Python ${{ matrix.python-version }}
Expand Down Expand Up @@ -115,10 +114,6 @@ jobs:
brew install git
echo "$(brew --prefix git)/bin" >> "$GITHUB_PATH"

- name: Prepare this repo for tests
run: |
./init-tests-after-clone.sh

- name: Set git user identity and command aliases for the tests
run: |
git config --global user.email "travis@ci.com"
Expand Down Expand Up @@ -219,6 +214,9 @@ jobs:
run: |
basedpyright --warnings

- name: Remove source Git metadata to verify fixture isolation
run: python -c "from pathlib import Path; from git.util import rmtree; rmtree('.git'); assert not Path('.git').exists()"

- name: Test with pytest
run: |
if [[ "$RUNNER_OS" == "Windows" && -z "${GIT_PYTHON_GIT_EXECUTABLE+x}" ]]; then
Expand Down
9 changes: 6 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
The following is a short step-by-step rundown of what one typically would do to contribute.

- [Fork this project](https://github.com/gitpython-developers/GitPython/fork) on GitHub.
- For setting up the environment to run the self tests, please run `init-tests-after-clone.sh`.
- Install the `test` extra and select a backend before running `pytest`. Test
repositories are generated automatically; no source Git history is required.
- Please try to **write a test that fails unless the contribution is present.**
- Try to avoid massive commits and prefer to take small steps, with one commit for each.
- Feel free to add yourself to AUTHORS file.
Expand Down Expand Up @@ -64,8 +65,10 @@ Put initial repository and filesystem states in `tests/fixtures/*.sh` and use
`test.lib.fixtures` to run them through `gix.testtools`. Read-only tests share
cached output; mutating tests use writable copies. Use `execute=True` only when
the fixture cannot be copied, and explain the reason at its call site. Keep
operations under test in Python. Immutable parser byte samples remain in
`test/fixtures`; generated caches and archives are ignored.
operations under test in Python. Generate histories from scratch and refer to
named fixture revisions; do not clone the source checkout, fetch project history,
or depend on its refs, object IDs, index, or working-tree state. Immutable parser
byte samples remain in `test/fixtures`; generated caches and archives are ignored.

Use `test.cleanup.cleanup_directory` for cleanup outside the shared fixture
owners. Close repository handles before removing their files. Cleanup is
Expand Down
8 changes: 2 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,8 @@ To clone the [the GitHub repository](https://github.com/gitpython-developers/Git
```sh
git clone https://github.com/gitpython-developers/GitPython
cd GitPython
./init-tests-after-clone.sh
```

On Windows, `./init-tests-after-clone.sh` can be run in a Git Bash shell.

If you are cloning [your own fork](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/about-forks), then replace the above `git clone` command with one that gives the URL of your fork. Or use this [`gh`](https://cli.github.com/) command (assuming you have `gh` and your fork is called `GitPython`):

```sh
Expand Down Expand Up @@ -175,9 +172,8 @@ See [Issue #525](https://github.com/gitpython-developers/GitPython/issues/525).

### RUNNING TESTS

_Important_: Right after cloning this repository, please be sure to have executed
the `./init-tests-after-clone.sh` script in the repository root. Otherwise
you will encounter test failures.
Test repositories are generated from scratch by fixture scripts. Tests work from
a shallow clone or a source copy without `.git`; no checkout preparation is needed.

#### Install test dependencies

Expand Down
4 changes: 4 additions & 0 deletions doc/gix-backend.md
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,10 @@ installation/import smoke coverage, including the Cygwin Python 3.9 job.
Running tests also requires Bash and Git 2.52+; `gix` here is GixPython's module.

Initial repository and filesystem states live in `tests/fixtures/*.sh`.
Histories are generated from scratch, including the shared sample repository and
its nested dependency repositories. Tests use named revisions such as `root`,
`release`, and `merge`, and require no source checkout history or Git metadata.
CI removes the source `.git` directory before running the full suite.
`test/lib/fixtures.py` calls `gix.testtools` with an explicit lifetime:

- `read_only_fixture()` and the default `fixture_repo()` reuse cached output.
Expand Down
3 changes: 3 additions & 0 deletions gitdb/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ The source is available in the GitPython repository on GitHub:

https://github.com/gitpython-developers/GitPython/tree/main/gitdb

Tests require Git and Bash. Each test class gets a temporary repository generated
from scratch with packed and loose objects; no source checkout history is needed.

Run the tests with::

pytest
Expand Down
14 changes: 14 additions & 0 deletions gitdb/gitdb/test/fixtures/repository.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/usr/bin/env bash
set -eu
git init -q --object-format=sha1 -b main repo
cd repo
for n in $(seq 1 30); do
Comment thread
Byron marked this conversation as resolved.
Resolved
printf 'revision %s\n' "$n" >> file
git add file
git commit -qm "Revision $n"
done
git gc --prune=now
# Keep both packed and loose objects for the compound database and tutorial tests.
printf 'loose object\n' > loose
git add loose
git commit -qm 'Add loose objects'
28 changes: 14 additions & 14 deletions gitdb/gitdb/test/lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import shutil
import os
import gc
import logging
import subprocess
from functools import wraps


Expand All @@ -30,28 +30,28 @@ class TestBase(unittest.TestCase):

* gitrepopath

* read-only base path of the git source repository, i.e. .../git/.git
* base path of a generated repository containing packed and loose objects
"""

#{ Invvariants
k_env_git_repo = "GITDB_TEST_GIT_REPO_BASE"
#} END invariants

@classmethod
def setUpClass(cls):
try:
super().setUpClass()
except AttributeError:
pass

cls.gitrepopath = os.environ.get(cls.k_env_git_repo)
if not cls.gitrepopath:
logging.info(
"You can set the %s environment variable to a .git repository of your choice - defaulting to the gitdb repository", cls.k_env_git_repo)
ospd = os.path.dirname
cls.gitrepopath = os.path.join(ospd(ospd(ospd(__file__))), '.git')
# end assure gitrepo is set
assert cls.gitrepopath.endswith('.git')
temporary = tempfile.TemporaryDirectory(prefix="gitdb-fixture-")
cls.addClassCleanup(temporary.cleanup)
env = {key: value for key, value in os.environ.items() if not key.startswith('GIT_')}
env.update(
GIT_CONFIG_NOSYSTEM='1', GIT_CONFIG_GLOBAL=os.devnull,
GIT_AUTHOR_NAME='GitDB Tests', GIT_AUTHOR_EMAIL='tests@example.invalid',
GIT_COMMITTER_NAME='GitDB Tests', GIT_COMMITTER_EMAIL='tests@example.invalid',
GIT_AUTHOR_DATE='2001-01-01T00:00:00 +0000', GIT_COMMITTER_DATE='2001-01-01T00:00:00 +0000',
)
# Keep the standalone suite usable on Python 3.8 without GixPython.
subprocess.run(['bash', fixture_path('repository.sh')], cwd=temporary.name, env=env, check=True)
cls.gitrepopath = os.path.join(temporary.name, 'repo', '.git')


#} END bases
Expand Down
4 changes: 2 additions & 2 deletions gitdb/gitdb/test/performance/test_pack.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def test_pack_random_access(self):
# END for each random mode

# query info and streams only
max_items = 10000 # can wait longer when testing memory
max_items = min(10000, ns) # can wait longer when testing memory
for pdb_fun in (pdb.info, pdb.stream):
st = time()
for sha in sha_list[:max_items]:
Expand All @@ -62,7 +62,7 @@ def test_pack_random_access(self):
# END for each function

# retrieve stream and read all
max_items = 5000
max_items = min(5000, ns)
pdb_stream = pdb.stream
total_size = 0
st = time()
Expand Down
6 changes: 3 additions & 3 deletions gitdb/gitdb/test/performance/test_pack_streaming.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@ def test_pack_writing(self):
# END gather objects for pack-writing
elapsed = time() - st
print("PDB Streaming: Got %i streams by sha in in %f s ( %f streams/s )" %
(ni, elapsed, ni / (elapsed or 1)), file=sys.stderr)
(count, elapsed, count / (elapsed or 1)), file=sys.stderr)

st = time()
PackEntity.write_pack((pdb.stream(sha) for sha in pdb.sha_iter()), ostream.write, object_count=ni)
PackEntity.write_pack((pdb.stream(sha) for sha in pdb.sha_iter()), ostream.write, object_count=pdb.size())
elapsed = time() - st
total_kb = ostream.bytes_written() / 1000
print(sys.stderr, "PDB Streaming: Wrote pack of size %i kb in %f s (%f kb/s)" %
Expand All @@ -78,4 +78,4 @@ def test_stream_reading(self):
elapsed = time() - st
total_kib = total_size / 1000
print(sys.stderr, "PDB Streaming: Got %i streams by sha and read all bytes totallying %i KiB ( %f KiB / s ) in %f s ( %f streams/s )" %
(ni, total_kib, total_kib / (elapsed or 1), elapsed, ni / (elapsed or 1)), sys.stderr)
(count, total_kib, total_kib / (elapsed or 1), elapsed, count / (elapsed or 1)), sys.stderr)
76 changes: 0 additions & 76 deletions init-tests-after-clone.sh

This file was deleted.

Loading
Loading