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

Unit tests #133

Merged
merged 3 commits into from
Jul 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
71 changes: 71 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# Contributing to this repo

## Setup

### Personal access token (PAT)

Follow [these](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token) instructions to configurate a personal access token.

Only permissions needed:
- public_repo

Save the token to a secure location. Click the "Configure SSO" button and "Authorize" if applicable.

### Config

```shell
cp config.example.json config.json

# Add your GitHub username and token
$EDITOR config.json

# Export the JSON credentials into an environment variable
export CONFIG=$(<config.json)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm unfamiliar with this syntax, so just checking that the lonely < is meant to be there?

```

## Virtual environment

### Install dependencies
Instructions for POSIX bash/zsh (see [here](https://docs.python.org/3/library/venv.html) for syntax for other shells):
```shell
python3 -m venv env
source env/bin/activate
python3 -m pip install --upgrade pip
python3 -m pip install -r requirements.txt -r dev-requirements.txt
source env/bin/activate
```

## Testing locally

```shell
PYTHONPATH=hubcap python -m pytest
```

## Run in test mode

```shell
export ENV=test
./cron.sh
```

### Optional configuration environment variables
```
# Default value is the `git-tmp` directory within the current working directory
# This directory will be deleted by default at the end of the run
export GIT_TMP=git-tmp
```

### Optional parameters
Preserve commits/build artifacts within the `$GIT_TMP` directory
```
export ENV=test
./cron.sh --no-cleanup
```

## Run in production mode

**WARNING:** Use with caution -- _will_ modify state.
```shell
export ENV=prod
./cron.sh
```
2 changes: 1 addition & 1 deletion config.example.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"name": "github_user",
"token": "pe4s0n@l-@cce$$-t0k3n"
},
"remote": "git@github.com:org/hub.getdbt.com.git",
"remote": "git@github.com:dbt-labs/hub.getdbt.com.git",
"push_branches": true,
"one_branch_per_repo": true
}
2 changes: 2 additions & 0 deletions dev-requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
black==22.6.0
pytest
Empty file added hubcap/__init__.py
Empty file.
File renamed without changes.
2 changes: 1 addition & 1 deletion hubcap/hubcap.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import package
import release_carrier

from cmd import *
from git_helper import *
from records import *

# ==
Expand Down
8 changes: 4 additions & 4 deletions hubcap/records.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'''Interface for objects useful to processing hub entries'''

import cmd
import git_helper
import hashlib
import json
import logging
Expand Down Expand Up @@ -71,7 +71,7 @@ def run(self, main_dir):
for tag in self.new_tags:
# go to repo dir to checkout tag and tag-commit specific package list
os.chdir(self.local_path_to_repo)
cmd.run_cmd(f'git checkout tags/{tag}')
git_helper.run_cmd(f'git checkout tags/{tag}')
packages = package.parse_pkgs(Path(os.getcwd()))

# return to hub and build spec
Expand All @@ -88,7 +88,7 @@ def run(self, main_dir):

msg = f'hubcap: Adding tag {tag} for {self.github_username}/{self.github_repo_name}'
logging.info(msg)
cmd.run_cmd('git add -A')
git_helper.run_cmd('git add -A')
subprocess.run(args=['git', 'commit', '-am', f'{msg}'], capture_output=True)

# if succesful return branchname
Expand All @@ -102,7 +102,7 @@ def cut_version_branch(self):

completed_subprocess = subprocess.run(['git', 'checkout', '-q', '-b', branch_name])
if completed_subprocess.returncode == 128:
run_cmd(f'git checkout -q {branch_name}')
git_helper.run_cmd(f'git checkout -q {branch_name}')

return branch_name

Expand Down
2 changes: 1 addition & 1 deletion hubcap/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import requests

from pathlib import Path
from cmd import *
from git_helper import *
from records import *

NOW = int(datetime.datetime.now().timestamp())
Expand Down
2 changes: 1 addition & 1 deletion hubcap/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import package

from cmd import *
from git_helper import *


def parse_semver_tag(tag):
Expand Down
Empty file added tests/__init__.py
Empty file.
111 changes: 111 additions & 0 deletions tests/test_version_regex.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
import pytest
from hubcap.version import is_valid_semver_tag


@pytest.fixture
def semver_20_valid():
"""Valid SemVer 2.0 versions"""
# Most test cases from https://regex101.com/r/Ly7O1x/3/
return [
# Begin test cases from https://regex101.com/r/Ly7O1x/3/
"0.0.4",
"1.2.3",
"10.20.30",
"1.1.2-prerelease+meta",
"1.1.2+meta",
"1.1.2+meta-valid",
"1.0.0-alpha",
"1.0.0-beta",
"1.0.0-alpha.beta",
"1.0.0-alpha.beta.1",
"1.0.0-alpha.1",
"1.0.0-alpha0.valid",
"1.0.0-alpha.0valid",
"1.0.0-alpha-a.b-c-somethinglong+build.1-aef.1-its-okay",
"1.0.0-rc.1+build.1",
"2.0.0-rc.1+build.123",
"1.2.3-beta",
"10.2.3-DEV-SNAPSHOT",
"1.2.3-SNAPSHOT-123",
"1.0.0",
"2.0.0",
"1.1.7",
"2.0.0+build.1848",
"2.0.1-alpha.1227",
"1.0.0-alpha+beta",
"1.2.3----RC-SNAPSHOT.12.9.1--.12+788",
"1.2.3----R-S.12.9.1--.12+meta",
"1.2.3----RC-SNAPSHOT.12.9.1--.12",
"1.0.0+0.build.1-rc.10000aaa-kk-0.1",
"99999999999999999999999.999999999999999999.99999999999999999",
"1.0.0-0A.is.legal",
# Begin custom test cases
"1.0.3-post1",
"0.8.0-a1",
"0.8.0-b2",
"0.8.0-rc3",
]


@pytest.fixture
def semver_20_invalid():
"""Invalid SemVer 2.0 versions"""
# Most test cases from https://regex101.com/r/Ly7O1x/3/
return [
# Begin test cases from https://regex101.com/r/Ly7O1x/3/
"1",
"1.2",
"1.2.3-0123",
"1.2.3-0123.0123",
"1.1.2+.123",
"+invalid",
"-invalid",
"-invalid+invalid",
"-invalid.01",
"alpha",
"alpha.beta",
"alpha.beta.1",
"alpha.1",
"alpha+beta",
"alpha_beta",
"alpha.",
"alpha..",
"beta",
"1.0.0-alpha_beta",
"-alpha.",
"1.0.0-alpha..",
"1.0.0-alpha..1",
"1.0.0-alpha...1",
"1.0.0-alpha....1",
"1.0.0-alpha.....1",
"1.0.0-alpha......1",
"1.0.0-alpha.......1",
"01.1.1",
"1.01.1",
"1.1.01",
"1.2",
"1.2.3.DEV",
"1.2-SNAPSHOT",
"1.2.31.2.3----RC-SNAPSHOT.12.09.1--..12+788",
"1.2-RC-SNAPSHOT",
"-1.0.3-gamma+b7718",
"+justmeta",
"9.8.7+meta+meta",
"9.8.7-whatever+meta+meta",
"99999999999999999999999.999999999999999999.99999999999999999----RC-SNAPSHOT.12.09.1--------------------------------..12",
# Begin custom test cases
"1.0.3.post1",
"0.8.0a1",
"0.8.0b2",
"0.8.0rc3",
Comment on lines +98 to +100
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

#130 will move these up to the "supported" category

]


def test_regex_valid(semver_20_valid):
for version in semver_20_valid:
assert is_valid_semver_tag(version)


def test_regex_invalid(semver_20_invalid):
for version in semver_20_invalid:
assert not is_valid_semver_tag(version)