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

Adding tests and GitHub actions #12

Merged
merged 32 commits into from
Mar 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
c19fc09
Merge pull request #11 from ecmwf/main
corentincarton Jan 11, 2024
ad3969a
added tests for init module
corentincarton Feb 14, 2024
78f6066
add github actions
corentincarton Feb 14, 2024
5fbcb49
minor formatting updatge
corentincarton Feb 14, 2024
0ca1af1
fix tests
corentincarton Feb 14, 2024
0eb1417
debug ci
corentincarton Feb 14, 2024
64b140d
debug ci
corentincarton Feb 14, 2024
168893b
debug ci
corentincarton Feb 14, 2024
d08b1cb
debug ci
corentincarton Feb 14, 2024
238009a
debug ci
corentincarton Feb 14, 2024
47d2656
debug ci
corentincarton Feb 14, 2024
9f6cbfd
debug ci
corentincarton Feb 14, 2024
81c058c
debug ci
corentincarton Feb 14, 2024
eef46e3
debug ci
corentincarton Feb 14, 2024
65a29af
debug ci
corentincarton Feb 14, 2024
271e92b
debug ci
corentincarton Feb 15, 2024
bfedb9d
debug ci
corentincarton Feb 15, 2024
f765331
debug ci
corentincarton Feb 15, 2024
70a32f0
debug ci
corentincarton Feb 15, 2024
dc71a56
debug ci
corentincarton Feb 15, 2024
50efc04
debug ci
corentincarton Feb 15, 2024
32de26b
debug ci
corentincarton Feb 15, 2024
aeef704
debug ci
corentincarton Feb 15, 2024
f43b576
minor change in run_cmd function
corentincarton Feb 15, 2024
40d1250
remove debug in github actions
corentincarton Feb 15, 2024
f0fa14d
Merge branch 'develop' of github.com:ecmwf/tracksuite into develop
corentincarton Feb 15, 2024
4254fcc
add test_deploy
corentincarton Feb 15, 2024
05dcdbf
debug on push github actions
corentincarton Feb 15, 2024
e62db1d
Update version.py
corentincarton Mar 5, 2024
8e9b668
update packaging
corentincarton Mar 5, 2024
cfe8922
debug tests
corentincarton Mar 5, 2024
8f831e8
Merge pull request #13 from ecmwf/feature/pyproject
corentincarton Mar 5, 2024
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
39 changes: 39 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: ci-tracksuite

# Controls when the workflow will run
on:
push:
branches: [ "master", "develop" ]
pull_request:
branches: [ "master", "develop" ]

jobs:
qa:
name: qa
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v4
- run: pip install black flake8 isort
- run: isort --check .
- run: black --check .
- run: flake8 .

setup:
name: setup
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
- run: python -m pip install .

test:
name: pytest
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
- run: git config --global user.email "[email protected]"
- run: git config --global user.name "Dummy User"
- run: python -m pip install .[test]
- run: python -m pytest . -v
56 changes: 56 additions & 0 deletions .github/workflows/on-push.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
name: on-push

on:
push:
branches:
- main
tags:
- "*"
pull_request:
branches:
- main

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

defaults:
run:
shell: bash -l {0}

jobs:
setup:
name: setup
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
- run: python -m pip install .

test:
name: pytest
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
- run: git config --global user.email "[email protected]"
- run: git config --global user.name "Dummy User"
- run: python -m pip install .[test]
- run: python -m pytest . -v

distribution:
runs-on: ubuntu-latest
needs: [setup, test]

steps:
- uses: actions/checkout@v3
- name: Build distributions
run: |
$CONDA/bin/python -m pip install build
$CONDA/bin/python -m build
- name: Publish a Python distribution to PyPI
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags')
uses: pypa/gh-action-pypi-publish@release/v1
with:
user: __token__
password: ${{ secrets.PYPI_API_TOKEN }}
48 changes: 38 additions & 10 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,13 +1,41 @@
[build-system]
# NOTE: `pip install build` to build with `python -m build`
requires = [
"setuptools >= 40.9.0",
"wheel"
]
requires = ["setuptools", "wheel"]
build-backend = "setuptools.build_meta"

[tool.pytest.ini_options]
addopts = ""
doctest_optionflags = ""
testpaths = "tests"
markers = []
[project]
name = "tracksuite"
version = "0.3.1"
description = "ecflow suite tracking and deploying toolkit"
authors = [
{ name = "European Centre for Medium-Range Weather Forecasts (ECMWF)", email = "[email protected]" },
{ name = "Corentin Carton de Wiart", email = "[email protected]" },
]
license = { text = "Apache License Version 2.0" }
requires-python = ">=3.8"
readme = "README.md"
classifiers = [
"Development Status :: 4 - Beta",
"Intended Audience :: Developers",
"License :: OSI Approved :: Apache Software License",
"Operating System :: Unix",
"Programming Language :: Python :: 3",
"Topic :: Scientific/Engineering",
]

dependencies = [
"gitpython >= 3.1.25"
]

[project.optional-dependencies]
test = ["pytest", "mocker", "pytest-mock"]

[project.urls]
"Source code" = "https://github.com/ecmwf/tracksuite"

[tool.setuptools.packages.find]
where = ["."]
exclude = ["tests"]

[project.scripts]
tracksuite-init = "tracksuite.init:main"
tracksuite-deploy = "tracksuite.deploy:main"
1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
gitpython >= 3.1.25
paramiko
25 changes: 0 additions & 25 deletions setup.cfg

This file was deleted.

3 changes: 0 additions & 3 deletions setup.py

This file was deleted.

160 changes: 160 additions & 0 deletions tests/test_deploy.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
import os
import tempfile

import git
import pytest

from tracksuite.deploy import GitDeployment
from tracksuite.init import setup_remote


@pytest.fixture
def git_deployment():

temp_dir = tempfile.TemporaryDirectory().name
staging_dir = os.path.join(temp_dir, "staging")
target_repo = os.path.join(temp_dir, "target")
current_user = os.getenv("USER")
setup_remote(
host="localhost",
user=current_user,
target_dir=target_repo,
)

deployer = GitDeployment(
host="localhost",
user=current_user,
staging_dir=staging_dir,
target_repo=target_repo,
)

return deployer


@pytest.fixture
def git_deployment_with_backup():

temp_dir = tempfile.TemporaryDirectory().name
staging_dir = os.path.join(temp_dir, "staging")
target_repo = os.path.join(temp_dir, "target")
backup_path = os.path.join(temp_dir, "backup.git")
git.Repo.init(backup_path, bare=True)
current_user = os.getenv("USER")
setup_remote(
host="localhost",
user=current_user,
target_dir=target_repo,
remote=backup_path,
)

deployer = GitDeployment(
host="localhost",
user=current_user,
staging_dir=staging_dir,
target_repo=target_repo,
backup_repo=backup_path,
)

return deployer


def test_git_deployment_constructor(git_deployment):

assert git_deployment.host == "localhost"
assert git_deployment.user == os.getenv("USER")
print(git_deployment.target_dir)
assert os.path.exists(git_deployment.target_dir)


def test_git_deployment_constructor_with_backup(git_deployment_with_backup):

assert git_deployment_with_backup.host == "localhost"
assert git_deployment_with_backup.user == os.getenv("USER")
print(git_deployment_with_backup.target_dir)
assert os.path.exists(git_deployment_with_backup.target_dir)
assert os.path.exists(git_deployment_with_backup.backup_repo)


def test_deploy_default(git_deployment):

deployer = git_deployment
staging_dir = deployer.staging_dir

os.mkdir(staging_dir)
with open(os.path.join(staging_dir, "dummy.txt"), "w") as f:
f.write("dummy content")

deployer.pull_remotes()
deployer.diff_staging()
deployer.deploy()

with open(os.path.join(deployer.target_dir, "dummy.txt"), "r") as f:
assert f.read() == "dummy content"

repo = git.Repo(deployer.target_dir)
commit_history = repo.iter_commits()
all_commits = [commit for commit in commit_history]
assert f"deployed by {deployer.user}" in all_commits[0].message


def test_deploy_message(git_deployment):

deployer = git_deployment
staging_dir = deployer.staging_dir

os.mkdir(staging_dir)
with open(os.path.join(staging_dir, "dummy.txt"), "w") as f:
f.write("dummy content")

deployer.pull_remotes()
deployer.diff_staging()
deployer.deploy("This is my change")

with open(os.path.join(deployer.target_dir, "dummy.txt"), "r") as f:
assert f.read() == "dummy content"

repo = git.Repo(deployer.target_dir)
commit_history = repo.iter_commits()
all_commits = [commit for commit in commit_history]
assert "This is my change" in all_commits[0].message


def test_deploy_with_backup(git_deployment_with_backup):

deployer = git_deployment_with_backup
staging_dir = deployer.staging_dir

os.mkdir(staging_dir)
with open(os.path.join(staging_dir, "dummy.txt"), "w") as f:
f.write("dummy content")

deployer.pull_remotes()
deployer.diff_staging()
deployer.deploy("This is my change")

with open(os.path.join(deployer.target_dir, "dummy.txt"), "r") as f:
assert f.read() == "dummy content"

repo = git.Repo(deployer.target_repo)
commit_history = repo.iter_commits()
all_commits = [commit for commit in commit_history]
assert "This is my change" in all_commits[0].message


def test_deploy_files(git_deployment):

deployer = git_deployment
staging_dir = deployer.staging_dir

os.mkdir(staging_dir)
for file in ["file1.txt", "file2.txt", "file3.txt"]:
with open(os.path.join(deployer.staging_dir, file), "w") as f:
f.write("dummy content")

deployer.pull_remotes()
deployer.diff_staging()
deployer.deploy(files=["file1.txt", "file2.txt"])

assert os.path.exists(os.path.join(deployer.target_dir, "file1.txt"))
assert os.path.exists(os.path.join(deployer.target_dir, "file2.txt"))
assert not os.path.exists(os.path.join(deployer.target_dir, "file3.txt"))
Loading
Loading