-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
245 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
--- | ||
name: GNE Standard Tests | ||
on: [push,pull_request] | ||
|
||
jobs: | ||
std_tests: | ||
name: std_tests | ||
runs-on: ubuntu-22.04 | ||
steps: | ||
- name: Checkout 'gne_tests' repository | ||
uses: actions/checkout@v4 | ||
|
||
- name: Checkout 'gne_exercises' repository (actions/checkout doesn't work) | ||
run: ./gh_actions.sh | ||
|
||
- name: "List files and directories" | ||
run: | | ||
pwd | ||
ls -al . | ||
ls -al .. | ||
- name: Setup python | ||
uses: actions/setup-python@v5 | ||
id: cp311 | ||
with: | ||
python-version: '3.11' | ||
architecture: x64 | ||
|
||
- name: Install Poetry | ||
uses: snok/install-poetry@v1 | ||
with: | ||
version: 1.7.1 | ||
virtualenvs-create: true | ||
virtualenvs-in-project: true | ||
|
||
- name: Cache Poetry virtualenv | ||
uses: actions/cache@v4 | ||
id: cached-poetry-dependencies | ||
with: | ||
path: .venv | ||
key: venv-${{ runner.os }}-cache-${{ steps.cp311.outputs.version }}-${{ hashFiles('**/poetry.lock') }} | ||
|
||
- name: Install Virtual Environment Dependencies | ||
run: poetry install -C gne_tests/ | ||
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true' | ||
|
||
- name: "List files and directories" | ||
run: | | ||
pwd | ||
ls -al . | ||
ls -al .. | ||
- name: View installed packages | ||
run: | | ||
poetry run python -m pip list | ||
- name: Run pylama on 'gne_tests' and 'gne_exercises' | ||
run: | | ||
poetry run pylama . | ||
poetry run pylama ../gne_exercises/ | ||
- name: Run black on 'gne_tests' and 'gne_exercises' | ||
run: | | ||
poetry run black --check . | ||
poetry run black --check ../gne_exercises/ | ||
- name: Per-lesson tests | ||
run: | | ||
poetry run pytest -s -v -x tests/ | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#!/bin/sh | ||
if [ "$GITHUB_ACTIONS" != "true" ]; then | ||
echo "Not running in GitHub Actions environment. Exiting..." | ||
exit 1 | ||
fi | ||
|
||
EXERCISE_DIR="gne_exercises" | ||
CURRENT_DIR=$(pwd) | ||
REPO="twin-bridges/gne_exercises" | ||
cd .. | ||
|
||
if [ ! -d "$EXERCISE_DIR" ]; then | ||
mkdir "$EXERCISE_DIR" | ||
fi | ||
|
||
if [ -d "$EXERCISE_DIR" ]; then | ||
cd "$EXERCISE_DIR" | ||
git init --initial-branch=main | ||
git remote add origin https://github.com/"$REPO" | ||
git pull origin main | ||
fi | ||
|
||
cd "$CURRENT_DIR" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,15 @@ | ||
from pathlib import Path | ||
import os | ||
|
||
HOME = Path.home() | ||
GIT = "/usr/bin/git" | ||
REPOSITORY = Path.home() / "gne_exercises" | ||
DEFAULT_BRANCH = "main" | ||
L4_REPOSITORY = Path.home() / "remotes_gne_exercises" | ||
REPOSITORY = HOME / "gne_exercises" | ||
L4_REPOSITORY = HOME / "remotes_gne_exercises" | ||
|
||
if os.getenv("GITHUB_ACTIONS"): | ||
# GH-Actions uses '/home/runner/work/gne_tests/gne_tests' | ||
# with the very final dir being the repo. | ||
HOME = HOME / "work" / "gne_tests" | ||
REPOSITORY = HOME / "gne_exercises" | ||
L4_REPOSITORY = HOME / "remotes_gne_exercises" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
import re | ||
|
||
from utilities import subprocess_runner, git_checkout | ||
from TEST_CONSTANTS import GIT, REPOSITORY | ||
|
||
|
||
def commit_change(file_name): | ||
cmd_list = [GIT, "add", file_name] | ||
std_out, _, _ = subprocess_runner(cmd_list, REPOSITORY, check_errors=True) | ||
|
||
cmd_list = [GIT, "commit", "-m", "TESTS: Lesson6, Ex3"] | ||
std_out, _, _ = subprocess_runner(cmd_list, REPOSITORY, check_errors=True) | ||
assert "TESTS: Lesson6, Ex3" in std_out | ||
assert "1 file changed, 0 insertions(+), 0 deletions(-)" in std_out | ||
assert "create mode 100644 test_lesson6_ex3.txt" in std_out | ||
|
||
# Clean 'git status' | ||
cmd_list = [GIT, "status"] | ||
std_out, _, _ = subprocess_runner(cmd_list, REPOSITORY, check_errors=True) | ||
assert "nothing to commit, working tree clean" in std_out | ||
|
||
|
||
def test_exercise1a(): | ||
commit = "983a8b7" | ||
git_checkout(commit) | ||
|
||
cmd_list = [GIT, "log", "--oneline"] | ||
std_out, _, _ = subprocess_runner(cmd_list, REPOSITORY, check_errors=True) | ||
git_log_line1 = std_out.splitlines()[0] | ||
assert re.search(r"983a8b7 Tag exercise", std_out) | ||
|
||
git_checkout(tag="v0.1") | ||
|
||
cmd_list = [GIT, "log", "--oneline"] | ||
std_out, _, _ = subprocess_runner(cmd_list, REPOSITORY, check_errors=True) | ||
git_log_line1 = std_out.splitlines()[0] | ||
assert re.search(r"983a8b7 Tag exercise", git_log_line1) | ||
|
||
git_checkout(branch="main") | ||
|
||
|
||
def test_exercise1b(): | ||
cmd_list = [GIT, "tag", "--list"] | ||
std_out, _, _ = subprocess_runner(cmd_list, REPOSITORY, check_errors=True) | ||
assert "v0.1" in std_out | ||
|
||
|
||
def test_exercise2a(): | ||
cmd_list = [GIT, "config", "--global", "init.defaultBranch", "test123"] | ||
std_out, _, _ = subprocess_runner(cmd_list, REPOSITORY, check_errors=True) | ||
|
||
cmd_list = [GIT, "config", "init.defaultBranch"] | ||
std_out, _, _ = subprocess_runner(cmd_list, REPOSITORY, check_errors=True) | ||
assert "test123" in std_out | ||
|
||
cmd_list = [GIT, "config", "--global", "init.defaultBranch", "main"] | ||
std_out, _, _ = subprocess_runner(cmd_list, REPOSITORY, check_errors=True) | ||
|
||
cmd_list = [GIT, "config", "init.defaultBranch"] | ||
std_out, _, _ = subprocess_runner(cmd_list, REPOSITORY, check_errors=True) | ||
assert "main" in std_out | ||
|
||
|
||
def test_exercise2b(): | ||
cmd_list = [GIT, "config", "--list"] | ||
std_out, _, _ = subprocess_runner(cmd_list, REPOSITORY, check_errors=True) | ||
assert "init.defaultbranch=main" in std_out | ||
assert "core.bare=false" in std_out | ||
|
||
|
||
def test_exercise2c(): | ||
cmd_list = [GIT, "config", "pull.rebase", "false"] | ||
std_out, _, _ = subprocess_runner(cmd_list, REPOSITORY, check_errors=True) | ||
|
||
cmd_list = [GIT, "config", "--list"] | ||
std_out, _, _ = subprocess_runner(cmd_list, REPOSITORY, check_errors=True) | ||
assert "pull.rebase=false" in std_out | ||
|
||
|
||
def test_exercise2d(): | ||
cmd_list = [GIT, "config", "--list", "--global"] | ||
std_out, _, _ = subprocess_runner(cmd_list, REPOSITORY, check_errors=True) | ||
assert "init.defaultbranch=main" in std_out | ||
|
||
cmd_list = [GIT, "config", "--list", "--local"] | ||
std_out, _, _ = subprocess_runner(cmd_list, REPOSITORY, check_errors=True) | ||
assert "pull.rebase=false" in std_out | ||
|
||
|
||
def test_exercise3(): | ||
# Ex 3a | ||
cmd_list = [GIT, "log", "--oneline"] | ||
std_out, _, _ = subprocess_runner(cmd_list, REPOSITORY, check_errors=True) | ||
first_line = std_out.splitlines()[0] | ||
original_commit = first_line.split()[0] | ||
|
||
file_name = "test_lesson6_ex3.txt" | ||
cmd_list = ["touch", file_name] | ||
std_out, _, _ = subprocess_runner(cmd_list, REPOSITORY, check_errors=True) | ||
|
||
commit_change(file_name) | ||
|
||
# Ex 3b | ||
cmd_list = [GIT, "reset", "--soft", "HEAD~1"] | ||
std_out, _, _ = subprocess_runner(cmd_list, REPOSITORY, check_errors=True) | ||
|
||
# Soft reset should restore the change to staging | ||
cmd_list = [GIT, "status"] | ||
std_out, _, _ = subprocess_runner(cmd_list, REPOSITORY, check_errors=True) | ||
pattern = re.escape(r"new file: test_lesson6_ex3.txt") | ||
assert re.search(pattern, std_out) | ||
|
||
# Ex 3c | ||
commit_change(file_name) | ||
|
||
# Ex 3d | ||
cmd_list = [GIT, "reset", "--mixed", "HEAD~1"] | ||
std_out, _, _ = subprocess_runner(cmd_list, REPOSITORY, check_errors=True) | ||
|
||
# Mixed reset should undo the commit and revert staging (unstage the file) | ||
cmd_list = [GIT, "status"] | ||
std_out, _, _ = subprocess_runner(cmd_list, REPOSITORY, check_errors=True) | ||
assert "Untracked files:" in std_out | ||
assert """use "git add <file>..." to include""" in std_out | ||
assert "test_lesson6_ex3.txt" in std_out | ||
|
||
# Ex 3e | ||
commit_change(file_name) | ||
|
||
# Ex 3f | ||
cmd_list = [GIT, "reset", "--hard", "HEAD~1"] | ||
std_out, _, _ = subprocess_runner(cmd_list, REPOSITORY, check_errors=True) | ||
assert f"HEAD is now at {original_commit}" in std_out | ||
|
||
cmd_list = [GIT, "status"] | ||
std_out, _, _ = subprocess_runner(cmd_list, REPOSITORY, check_errors=True) | ||
assert "nothing to commit, working tree clean" in std_out |