Skip to content

Commit 17180e7

Browse files
committed
test: ✅ move template test into own file and update it
1 parent 265bcaa commit 17180e7

File tree

2 files changed

+84
-54
lines changed

2 files changed

+84
-54
lines changed

justfile

Lines changed: 3 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -46,60 +46,9 @@ check-commits:
4646
check-spelling:
4747
uvx typos
4848

49-
# Test and check that a Python package can be created from the template
50-
test is_seedcase_project:
51-
#!/bin/zsh
52-
test_name="test-python-package"
53-
test_dir="$(pwd)/_temp/{{ is_seedcase_project }}/$test_name"
54-
template_dir="$(pwd)"
55-
commit=$(git rev-parse HEAD)
56-
rm -rf $test_dir
57-
# vcs-ref means the current commit/head, not a tag.
58-
uvx copier copy $template_dir $test_dir \
59-
--vcs-ref=$commit \
60-
--defaults \
61-
--trust \
62-
--data package_github_repo="first-last/repo" \
63-
--data is_seedcase_project={{ is_seedcase_project }} \
64-
--data author_given_name="First" \
65-
--data author_family_name="Last" \
66-
--data author_email="[email protected]" \
67-
--data review_team="@first-last/developers" \
68-
--data github_board_number=22
69-
# Run checks in the generated test Python package
70-
cd $test_dir
71-
git add .
72-
git commit -m "test: initial copy"
73-
just check-python check-spelling
74-
# TODO: Find some way to test the `update` command
75-
# Check that recopy works
76-
echo "Testing recopy command -----------"
77-
rm .cz.toml
78-
git add .
79-
git commit -m "test: preparing to recopy from the template"
80-
uvx copier recopy \
81-
--vcs-ref=$commit \
82-
--defaults \
83-
--overwrite \
84-
--trust
85-
# Check that copying onto an existing Python package works
86-
echo "Using the template in an existing package command -----------"
87-
rm .cz.toml .copier-answers.yml LICENSE.md
88-
git add .
89-
git commit -m "test: preparing to copy onto an existing package"
90-
uvx copier copy \
91-
$template_dir $test_dir \
92-
--vcs-ref=$commit \
93-
--defaults \
94-
--trust \
95-
--overwrite \
96-
--data package_github_repo="first-last/repo" \
97-
--data is_seedcase_project={{ is_seedcase_project }} \
98-
--data author_given_name="First" \
99-
--data author_family_name="Last" \
100-
--data author_email="[email protected]" \
101-
--data review_team="@first-last/developers" \
102-
--data github_board_number=22
49+
# Test that a Python package can be created from the template, with parameters for: `is_seedcase_project` (true or false) and `hosting_provider` (either "gh-pages" or "netlify")
50+
test is_seedcase_project="true" hosting_provider="netlify":
51+
sh ./test-template.sh {{ is_seedcase_project }} {{ hosting_provider }}
10352

10453
# Clean up any leftover and temporary build files
10554
cleanup:

test-template.sh

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
#!/usr/bin/env bash
2+
3+
# Needs two arguments:
4+
#
5+
# 1. is_seedcase_project: true or false
6+
# 2. hosting_provider: e.g., "github", "gitlab", etc.
7+
8+
# Argument naming -----
9+
is_seedcase_project="${1}"
10+
hosting_provider="${2}"
11+
12+
if [ -z "$is_seedcase_project" ] || [ -z "$hosting_provider" ]; then
13+
echo "Usage: sh $0 <is_seedcase_project> <hosting_provider>"
14+
echo "Example: sh $0 true netlify"
15+
exit 1
16+
fi
17+
18+
# Set up variables and functions for the test -----
19+
test_name="test-package-$hosting_provider"
20+
test_dir="$(pwd)/_temp/$is_seedcase_project/$test_name"
21+
template_dir="$(pwd)"
22+
# Use the latest commit for the template
23+
commit=$(git rev-parse HEAD)
24+
25+
# Needs three arguments:
26+
#
27+
# 1. Template directory
28+
# 2. Destination directory
29+
# 3. VCS ref (commit, branch, tag, etc.)
30+
copy () {
31+
# vcs-ref means the current commit/head, not a tag.
32+
uvx copier copy $1 $2 \
33+
--vcs-ref=$3 \
34+
--defaults \
35+
--data package_github_repo="first-last/repo" \
36+
--data is_seedcase_project=$is_seedcase_website \
37+
--data author_given_name="First" \
38+
--data author_family_name="Last" \
39+
--data author_email="[email protected]" \
40+
--data review_team="@first-last/developers" \
41+
--data github_board_number=22 \
42+
--overwrite \
43+
--skip-tasks \
44+
--trust
45+
}
46+
47+
# Pre-test setup -----
48+
# Remove the leftover directory from previous runs
49+
rm -rf $test_dir
50+
mkdir -p $test_dir
51+
52+
# Check initial creation -----
53+
# TODO: Find some way to test the `update` command
54+
# Any step that fails will exit the script with an error and not continue
55+
echo "Testing copy for new projects when: 'is_seedcase_project'='$is_seedcase_project', 'hosting_provider'='$hosting_provider' -----------"
56+
(
57+
cd $test_dir &&
58+
copy $template_dir $test_dir $commit &&
59+
git init -b main &&
60+
git add . &&
61+
git commit --quiet -m "test: initial copy" &&
62+
# Check that recopy works -----
63+
echo "Testing recopy when: 'is_seedcase_project'='$$is_seedcase_project', 'hosting_provider'='$hosting_provider' -----------" &&
64+
rm .cz.toml &&
65+
git add . &&
66+
git commit --quiet -m "test: preparing to recopy from the template" &&
67+
uvx copier recopy \
68+
--vcs-ref=$commit \
69+
--defaults \
70+
--overwrite \
71+
--skip-tasks \
72+
--trust &&
73+
# Check that copying onto an existing package works -----
74+
echo "Testing copy in existing projects when: 'is_seedcase_project'='$is_seedcase_project', 'hosting_provider'='$hosting_provider' -----------" &&
75+
rm .cz.toml .copier-answers.yml &&
76+
git add . &&
77+
git commit --quiet -m "test: preparing to copy onto an existing package" &&
78+
copy $template_dir $test_dir $commit #&&
79+
# Checks and builds -----
80+
# just run-all
81+
)

0 commit comments

Comments
 (0)