Skip to content

Commit

Permalink
Merge pull request #49 from nikromen/add-tests
Browse files Browse the repository at this point in the history
Add tests
  • Loading branch information
nikromen authored May 12, 2023
2 parents 39e4329 + 0daeace commit be7a7bb
Show file tree
Hide file tree
Showing 21 changed files with 502 additions and 151 deletions.
19 changes: 18 additions & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:
- main

jobs:
test-cases:
test:
runs-on: ubuntu-latest
strategy:
fail-fast: false
Expand All @@ -21,9 +21,26 @@ jobs:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
sudo apt-get install -y git
python -m pip install --upgrade pip
python -m pip install poetry
poetry install
- name: Run tests
run: |
poetry run pytest -vvv test/
check-install:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-versions: ["3.9", "3.11"]

steps:
- uses: actions/checkout@v3
- name: Set up Python --version ${{ matrix.python-version }}
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}
- name: Test if alpa installs on Ubuntu
run: pip install . && alpa --help
3 changes: 1 addition & 2 deletions Containerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# this containerfile is only for testing purposes


FROM fedora:latest

# here will be the copied files from alpa
Expand All @@ -10,6 +9,6 @@ COPY . /alpa/alpa_copy
# bind local alpa project to this directory to tinker with it
RUN mkdir -p /alpa/alpa_bind

RUN dnf install -y make git pip poetry
RUN dnf install -y make git pip poetry pytest
# install package dependencies (first enter poetry shell -> `$ poetry shell`)
RUN poetry install
9 changes: 6 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ IMAGE_NAME=alpa-test
CONTAINER_ENGINE ?= $(shell command -v podman 2> /dev/null || echo docker)


# regenerate new image when needed
build-image:
$(CONTAINER_ENGINE) build --rm --tag $(IMAGE_NAME) -f Containerfile

Expand All @@ -12,7 +13,7 @@ enter-image:


check-tests:
poetry shell && pytest -vvv test/
$(CONTAINER_ENGINE) run -ti $(IMAGE_NAME) bash -c "poetry run pytest -vvv test/"


check-install:
Expand All @@ -23,5 +24,7 @@ check-install:
check: check-install check-tests


container-check: build-image
$(CONTAINER_ENGINE) run -ti $(IMAGE_NAME) make check
ci-check-install: build-image check-install


ci-check-tests: build-image check-tests
2 changes: 1 addition & 1 deletion alpa.spec
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Name: alpa
Version: 0.9.1
Version: 0.10.0
Release: 1%{?dist}
Summary: Integration tool with Alpa repository

Expand Down
5 changes: 2 additions & 3 deletions alpa/cli/local_repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,12 @@ def switch(name: str) -> None:
default="",
help="Your commit message not longer than 80 characters.",
)
@click.option("-n", "--no-verify", is_flag=True, help="Do not run pre-commit")
def commit(message: str, no_verify: bool) -> None:
def commit(message: str) -> None:
"""Commit your changes in your package's repository"""
if len(message) > 80:
raise ClickException("Message longer than 80 characters")

LocalRepoBranch(Path(getcwd())).commit(message, not no_verify)
LocalRepoBranch(Path(getcwd())).commit(message)


@click.command("add")
Expand Down
19 changes: 9 additions & 10 deletions alpa/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,14 @@
ALPA_CONFIG_FILE_NAMES = [".alpa.yaml", ".alpa.yml", "alpa.yaml", "alpa.yml"]

REQUEST_LABEL = "request"
CREATE_PACKAGE_REQUEST_TITLE = (
"[alpa request-new-package] New request to create a package {package_name}"
)
DELETE_PACKAGE_REQUEST_TITLE = (
"[alpa delete-package] New request to delete a package {package_name}"
)


class PackageRequest(str, Enum):
TITLE = "[alpa request-new-package] New request for package {package_name}"
BODY = "@{user} requested {package_name}"
LABEL = REQUEST_LABEL


class DeleteRequest(str, Enum):
TITLE = "[alpa delete-package] New request for deleting package {package_name}"
BODY = "@{user} requested to delete {package_name}"
LABEL = REQUEST_LABEL
class RequestEnum(str, Enum):
delete = "delete"
create = "create"
31 changes: 26 additions & 5 deletions alpa/repository/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import logging
import subprocess
from abc import ABC, abstractmethod
from json import dumps
from os import getcwd
from pathlib import Path
from typing import Optional, Iterable
Expand All @@ -19,6 +20,10 @@
ALPA_FEAT_BRANCH_PREFIX,
ORIGIN_NAME,
UPSTREAM_NAME,
RequestEnum,
REQUEST_LABEL,
DELETE_PACKAGE_REQUEST_TITLE,
CREATE_PACKAGE_REQUEST_TITLE,
)
from alpa.gh import GithubAPI, GithubRepo
from alpa.git import GitCMD
Expand Down Expand Up @@ -237,7 +242,7 @@ def branch_exists(self, branch: str) -> bool:
def get_history_of_branch(self, branch: str, params: list[str]) -> str:
return self.git_cmd(["log", "--decorate", "--graph"] + params + [branch]).stdout

def commit(self, message: str, pre_commit: bool) -> bool:
def commit(self, message: str) -> bool:
packit_conf = Packit(self.package)
if not packit_conf.packit_config_file_exists():
packit_conf.create_packit_config()
Expand Down Expand Up @@ -321,13 +326,29 @@ def __init__(self, repo_path: Path, gh_api: Optional[GithubAPI] = None) -> None:
def create_package(self, package: str) -> None:
pass

@abstractmethod
def _request_package_action(self, request_type: RequestEnum, pkg: str) -> None:
ensured_upstream = self.gh_repo.get_root_repo()
upstream_namespace = ensured_upstream.namespace
issue_repo = self.gh_api.get_repo(upstream_namespace, self.gh_repo.repo_name)

if request_type == RequestEnum.delete:
title = DELETE_PACKAGE_REQUEST_TITLE.format(package_name=pkg)
else:
title = CREATE_PACKAGE_REQUEST_TITLE.format(package_name=pkg)

body = {
"request_type": request_type,
"user": self.gh_api.gh_user,
"package": pkg,
}
issue = issue_repo.create_issue(title, dumps(body))
issue.add_to_labels(REQUEST_LABEL)

def request_package(self, package_name: str) -> None:
pass
self._request_package_action(RequestEnum.create, package_name)

@abstractmethod
def request_package_delete(self, package: str) -> None:
pass
self._request_package_action(RequestEnum.delete, package)

@staticmethod
def _prepare_cloned_repo(where_to_clone: str, gh_repo: GithubRepo) -> None:
Expand Down
26 changes: 1 addition & 25 deletions alpa/repository/branch.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from pathlib import Path
import re
from typing import Optional, Type
from typing import Optional

from click import ClickException
import click
Expand All @@ -14,9 +14,6 @@
from alpa.constants import (
ALPA_FEAT_BRANCH_PREFIX,
MAIN_BRANCH,
PackageRequest,
DeleteRequest,
REQUEST_LABEL,
)
from alpa.gh import GithubAPI
from alpa.messages import NO_WRITE_ACCESS_ERR
Expand Down Expand Up @@ -145,24 +142,3 @@ def create_package(self, package: str) -> None:
self.git_cmd(["switch", "-c", package])
self.git_cmd(["push", self.remote_name, package])
click.echo(f"Package {package} created")

def _request_package_action(
self, action: Type[PackageRequest | DeleteRequest], pkg: str
) -> None:
ensured_upstream = self.gh_repo.get_root_repo()
upstream_namespace = ensured_upstream.namespace
issue_repo = self.gh_api.get_repo(upstream_namespace, self.gh_repo.repo_name)
issue = issue_repo.create_issue(
action.TITLE.value.format(package_name=pkg),
action.BODY.value.format(
user=self.gh_api.gh_user,
package_name=pkg,
),
)
issue.add_to_labels(REQUEST_LABEL)

def request_package(self, package_name: str) -> None:
self._request_package_action(PackageRequest, package_name)

def request_package_delete(self, package: str) -> None:
self._request_package_action(DeleteRequest, package)
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "pyalpa"
version = "0.9.1"
version = "0.10.0"
description = "Integration tool with Alpa repository"
authors = ["Jiri Kyjovsky <[email protected]>"]
maintainers = ["Jiří Kyjovský <[email protected]>"]
Expand Down
2 changes: 0 additions & 2 deletions test/config.py

This file was deleted.

Empty file removed test/conftest.py
Empty file.
18 changes: 9 additions & 9 deletions test/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
anytia_backend: pypi
targets_notify_on_fail:
- f36
- centos
- fedora-36
- centos-stream
maintainers:
- user:
Expand All @@ -17,9 +17,9 @@
email: [email protected]
targets:
- f37
- f36
- centos
- fedora-37
- fedora-36
- centos-stream
arch:
- x86_64
Expand All @@ -38,9 +38,9 @@
email: [email protected]
targets:
- f37
- f36
- centos
- fedora-37
- fedora-36
- centos-stream
"""


Expand Down Expand Up @@ -72,7 +72,7 @@
allow_foreign_contributing: true
targets:
- f32
- fedora-32
arch:
- aarch64
Expand Down
Loading

0 comments on commit be7a7bb

Please sign in to comment.