Skip to main content

A tool for cloning and testing repositories (docker or local, interface is the same).

Project description

repotest

A library for automating test execution and repository operations.

It simplifies working with Docker and local repositories and provides utilities for managing patches and tests.

Originally built to facilitate LLM generation testing at the repository level, aimed at easing workflows for data scientists.


Installation

If you're running on an ECS GigaCode worker, please run:

ln -s /data/adam/.cache/repotest ~/.cache/repotest

This is necessary due to limited disk space.

  1. Install the latest version using pip:
pip install dist/$(ls dist/repotest-*.whl | sort -V | tail -n 1)

This command installs the latest available version of the package. It's equivalent to pip install dist/repotest-0.2.6-py3-none-any.whl, but always picks the latest version.

  1. To run the project in debug mode, add the current folder to the Python path:
import sys
sys.path.append("/path/to/repotest")
  1. Check which modes work on your current machine:
from repotest.scripts import check_perfomance

Design

The following diagram shows the architecture of the project and how different components interact:


How to Clean All Caches

from repotest.utils.clean import remove_all_containers, remove_all_images, clean_all, ...

Example Usage

The project supports two execution modes: Docker-based and local.

Using Docker:

from repotest.core.docker.java import JavaDockerRepo 

repo = JavaDockerRepo(
    repo="Osiris-Team/SPPU",
    base_commit="1a86a84e3c2dd7446b4778db8bb5dbaf44944f1c",
    image_name="maven:3.9.9-eclipse-temurin-23-alpine"
)

repo.clean()  # Reset the repo folder to the base commit state
# repo.build_env("", timeout=60*5)  # Set up the environment
# repo.apply_patch(patch)  # Apply a patch to the repo
repo.run_test("mvn test", timeout=60*5)  # Run tests with a 5-min timeout

Using Local Filesystem:

from repotest.core.local.java import JavaLocalRepo

repo = JavaLocalRepo(
    repo="Osiris-Team/SPPU",
    base_commit="1a86a84e3c2dd7446b4778db8bb5dbaf44944f1c",
)

repo.clean()  # Reset the repo folder to the base commit state
# repo.build_env("", timeout=60*5)
# repo.apply_patch(patch)
repo.run_test("mvn test", timeout=60*5)

The interface for *Repo classes is the same across modes.

The only difference is that JavaDockerRepo allows specifying an image and cache volumes. By default, Maven cache is stored in a Docker volume.


Creating Git Patches for Java Projects

The following code generates a git patch from changes in the repository:

from repotest.utils.git.git_diff_wrapper import GitDiffWrapper

changer = GitDiffWrapper(
    repo=task['repo_name'], 
    base_commit=task['base_commit']
)

changer.change_test(
    fn_test=task['test_file'], 
    str_test=task['output'], 
    str_source=task['source_code']
)

changer.fix_pom_file()
patch = changer.git_diff()

Logs

All logs are saved to: repotest/logs/%Y-%m-%d.log Only critical logs are printed to stdout by default.

To increase verbosity and print logs to stdout:

from repotest.logger import change_console_logger_level
from logging import DEBUG

change_console_logger_level(DEBUG)

Build the Package from Source

To build the package from source:

python -m build

Run Tests

Tests follow the same file structure as the main library. To run them (takes ~1–2 minutes):

pytest tests

Dataset Overview

All datasets used for testing the library are stored in ../datasets/*.json. Example of how to load one:

from datasets import load_dataset
ds = load_dataset('json', data_files="../datasets/java_from_1_2k_from_parser.jsonl")

Enable/Disable Stdout Logs

By default, logs are stored in ~/.cache/repotest/logs/{date}.log.

To toggle stdout logging:

from repotest.constants import enable_stdout_logs, disable_stdout_logs

enable_stdout_logs()
disable_stdout_logs()

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

repositorytest-0.4.6-py3-none-any.whl (71.7 kB view details)

Uploaded Python 3

File details

Details for the file repositorytest-0.4.6-py3-none-any.whl.

File metadata

  • Download URL: repositorytest-0.4.6-py3-none-any.whl
  • Upload date:
  • Size: 71.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.13

File hashes

Hashes for repositorytest-0.4.6-py3-none-any.whl
Algorithm Hash digest
SHA256 f47fd778fb35c51e3acce6901df8020ee1d3124ccee3b4f0b5d122e5950288b3
MD5 c2df9e07d5b7aa8796fc5932c7edd1ea
BLAKE2b-256 029ddf0a8633e6bb945de096b9298e357b61a90dec842f7f06fe4c44dc9049c0

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page