Skip to content

Commit

Permalink
Merge pull request #506 from JrGoodle/tests
Browse files Browse the repository at this point in the history
Add groups tests
  • Loading branch information
JrGoodle committed May 19, 2020
2 parents 3f06f7c + 4cdbfc7 commit 8ae63f2
Show file tree
Hide file tree
Showing 48 changed files with 1,262 additions and 40 deletions.
55 changes: 55 additions & 0 deletions .github/workflows/ci-cats-groups.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
name: 'CI - cats groups'

on:
push:
branches:
- master
paths-ignore:
- 'docs/**'
pull_request:
branches:
- master
paths-ignore:
- 'docs/**'

defaults:
run:
shell: bash

jobs:
cats_groups:
env:
PYTHON_VERSION: ${{ matrix.python-version }}
OS_NAME: ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [macos-latest, ubuntu-latest] # TODO: windows-latest
python-version: ['3.6', '3.7', '3.8']
exclude:
- os: macos-latest
python-version: '3.6'
- os: macos-latest
python-version: '3.8'
steps:
- uses: actions/checkout@v2
- name: Setup python
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Setup git config
run:
git config --global user.email "joe@polka.cat";
git config --global user.name "GitHub Actions Workflow"
- name: Install clowder requirements
run: pip3 install -r src/requirements.txt
- name: CI before script
run: script/ci_before
- name: Install clowder
run: script/update
- name: Install clowder test
run: script/test
- name: Test groups commands
run: clowder-test -c cats groups
- name: CI after script
run: script/ci_after
8 changes: 8 additions & 0 deletions clowder_test/clowder_test/cli/cats_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,14 @@ def forall(self) -> None:

self._execute_command('./forall.sh', self.path)

@expose(
help='Run cats groups tests'
)
def groups(self) -> None:
"""clowder cats groups tests"""

self._execute_command('./groups.sh', self.path)

@expose(
help='Run cats help tests'
)
Expand Down
1 change: 1 addition & 0 deletions examples/cats/clean.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ rm -rf .clowder
rm -rf black-cats
rm -rf duke
rm -rf mu
rm -rf mu-cat
rm -rf kit
rm -rf kishka
rm -rf june
Expand Down
3 changes: 3 additions & 0 deletions examples/cats/init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,7 @@ if [ -z "$COMMAND" ]; then
COMMAND='clowder'
fi

declare -f begin_command > /dev/null && begin_command
$COMMAND init https://github.com/jrgoodle/cats.git || exit 1
declare -f end_command > /dev/null && end_command
exit # Don't propagate error
3 changes: 3 additions & 0 deletions examples/misc/init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,7 @@ if [ -z "$COMMAND" ]; then
COMMAND='clowder'
fi

declare -f begin_command > /dev/null && begin_command
$COMMAND init https://github.com/jrgoodle/misc-clowder-tests.git || exit 1
declare -f end_command > /dev/null && end_command
exit # Don't propagate error
3 changes: 3 additions & 0 deletions examples/swift-projects/init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,7 @@ if [ -z "$COMMAND" ]; then
COMMAND='clowder'
fi

declare -f begin_command > /dev/null && begin_command
$COMMAND init https://github.com/jrgoodle/swift-clowder.git -b test || exit 1
declare -f end_command > /dev/null && end_command
exit # Don't propagate error
29 changes: 21 additions & 8 deletions src/clowder/cli/status.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,27 @@
"""

import argparse
from typing import Tuple

import clowder.clowder_repo as clowder_repo
from clowder.clowder_controller import CLOWDER_CONTROLLER, ClowderController
from clowder.util.clowder_utils import add_parser_arguments
from clowder.clowder_controller import CLOWDER_CONTROLLER
from clowder.model.project import Project
from clowder.util.clowder_utils import (
add_parser_arguments,
filter_projects,
options_help_message
)
from clowder.util.connectivity import network_connection_required
from clowder.util.decorators import valid_clowder_yaml_required


def add_status_parser(subparsers: argparse._SubParsersAction) -> None: # noqa

arguments = [
(['projects'], dict(metavar='PROJECT', default='all', nargs='*',
choices=CLOWDER_CONTROLLER.project_choices,
help=options_help_message(CLOWDER_CONTROLLER.project_names,
'projects and groups to print status of'))),
(['--fetch', '-f'], dict(action='store_true', help='fetch projects before printing status'))
]

Expand All @@ -35,27 +45,30 @@ def status(args) -> None:
def _status(args) -> None:
"""Clowder status command private implementation"""

projects = filter_projects(CLOWDER_CONTROLLER.projects, args.projects)

if args.fetch:
_fetch_projects(CLOWDER_CONTROLLER)
_fetch_projects(projects)
else:
clowder_repo.print_status()

padding = len(max(CLOWDER_CONTROLLER.get_all_project_paths(), key=len))
padding = len(max(CLOWDER_CONTROLLER.get_project_paths(projects), key=len))

for project in CLOWDER_CONTROLLER.projects:
for project in projects:
print(project.status(padding=padding))


@network_connection_required
def _fetch_projects(clowder: ClowderController) -> None:
def _fetch_projects(projects: Tuple[Project, ...]) -> None:
"""fetch all projects
:param ClowderController clowder: ClowderController instance
:param Tuple[Project, ...] projects: Projects to fetch
"""

clowder_repo.print_status(fetch=True)

print(' - Fetch upstream changes for projects\n')
for project in clowder.projects:
for project in projects:
print(project.status())
project.fetch_all()
print()
9 changes: 5 additions & 4 deletions src/clowder/clowder_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,16 @@ def get_all_fork_project_names(self) -> Tuple[str, ...]:
except TypeError:
return ()

def get_all_project_paths(self) -> Tuple[str, ...]:
"""Returns all project paths for current clowder.yaml
def get_project_paths(self, projects: Tuple[Project, ...]) -> Tuple[str, ...]: # noqa
"""Returns all project paths for specified projects
:param Tuple[Project, ... projects: Projects to get paths of
:return: All project paths
:rtype: Tuple[str, ...]
"""

try:
return tuple(sorted([p.formatted_project_path() for p in self.projects]))
return tuple(sorted([p.formatted_project_path() for p in projects]))
except TypeError:
return ()

Expand Down Expand Up @@ -119,7 +120,7 @@ def get_yaml(self, resolved: bool = False) -> dict:
def validate_print_output(self, project_names: Tuple[str, ...]) -> None:
"""Validate projects/groups and print output
:param Optional[List[str]] project_names: Project names to validate/print
:param Tuple[str, ...] project_names: Project names to validate/print
"""

projects = filter_projects(self.projects, project_names)
Expand Down
5 changes: 3 additions & 2 deletions src/clowder/model/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,14 @@ def __init__(self, project: dict, defaults: Defaults, sources: Tuple[Source, ...
self._commit = defaults.commit
self.ref = defaults.ref

groups = [self.name, 'all']
groups = ['all', self.name, fmt.last_path_component(self.name), self.path]
custom_groups = project.get('groups', None)
if custom_groups:
groups += custom_groups
groups = list(set(groups))
if 'notdefault' in groups:
groups.remove('all')
self.groups = list(set(groups))
self.groups = groups

self.source = None
source_name = project.get('source', defaults.source)
Expand Down
27 changes: 27 additions & 0 deletions test/scripts/cats/branch.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,39 @@ $COMMAND herd $PARALLEL || exit 1
print_double_separator
echo "TEST: Test clowder branch"

begin_command
$COMMAND branch || exit 1
end_command

begin_command
$COMMAND branch -r || exit 1
end_command

begin_command
$COMMAND branch -a || exit 1
end_command

begin_command
$COMMAND branch 'jrgoodle/mu' 'jrgoodle/duke' || exit 1
end_command

begin_command
$COMMAND branch -r 'jrgoodle/mu' 'jrgoodle/duke' || exit 1
end_command

begin_command
$COMMAND branch -a 'jrgoodle/mu' 'jrgoodle/duke' || exit 1
end_command

begin_command
$COMMAND branch 'black-cats' || exit 1
end_command

begin_command
$COMMAND branch -r 'black-cats' || exit 1
end_command

begin_command
$COMMAND branch -a 'black-cats' || exit 1
end_command

11 changes: 11 additions & 0 deletions test/scripts/cats/checkout.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,17 @@ echo "TEST: Test clowder checkout"
cd "$CATS_EXAMPLE_DIR" || exit 1
./clean.sh
./init.sh || exit 1

begin_command
$COMMAND herd $PARALLEL || exit 1
end_command

test_checkout() {
print_single_separator
echo "TEST: Check projects are on correct branches"
begin_command
$COMMAND herd $PARALLEL || exit 1
end_command
local branch='checkout_branch'

pushd duke || exit 1
Expand All @@ -55,7 +60,9 @@ test_checkout() {

test_cats_default_herd_branches

begin_command
$COMMAND checkout $branch || exit 1
end_command

pushd duke || exit 1
test_branch $branch || exit 1
Expand All @@ -69,8 +76,12 @@ test_checkout() {
popd || exit 1
done

begin_command
$COMMAND checkout knead jrgoodle/mu || exit 1
end_command
begin_command
$COMMAND checkout purr jrgoodle/duke || exit 1
end_command

test_cats_default_herd_branches
}
Expand Down

0 comments on commit 8ae63f2

Please sign in to comment.