-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- add project example test - add parallel tests - add structure tests
- Loading branch information
Showing
15 changed files
with
1,014 additions
and
4 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
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,13 @@ | ||
install: | ||
- name: install-step | ||
|
||
foo: <foo> | ||
bar-foo: <bar.foo> | ||
|
||
shell: | | ||
echo foo | ||
test: | ||
- name: test-step | ||
shell: | | ||
echo bar |
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,7 @@ | ||
foo: | ||
- 1 | ||
- 2 | ||
- 3 | ||
|
||
foo-bar: | ||
foo: 5 |
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,4 @@ | ||
foo: | ||
- 1 | ||
- 2 | ||
- 3 |
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 @@ | ||
foo: 1 |
File renamed without changes.
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,71 @@ | ||
#!/bin/python3 | ||
# author: Jan Hybs | ||
|
||
import tests | ||
|
||
import random | ||
from os.path import join | ||
|
||
from unittest import TestCase | ||
from cfg import cfgutil | ||
|
||
|
||
project_dir = join(tests.__dir__, 'project-example') | ||
config_path = join(project_dir, 'config.yaml') | ||
|
||
|
||
class TestConfig(TestCase): | ||
|
||
def test_configure_file(self): | ||
|
||
variables = dict() | ||
project_configs = list(cfgutil.configure_file(config_path, variables)) | ||
self.assertEqual(len(project_configs), 1) | ||
|
||
variables = cfgutil.load_config(join(project_dir, 'variables-simple.yaml')) | ||
project_configs = list(cfgutil.configure_file(config_path, variables)) | ||
self.assertEqual(len(project_configs), 1) | ||
|
||
variables = cfgutil.load_config(join(project_dir, 'variables-iter.yaml')) | ||
project_configs = list(cfgutil.configure_file(config_path, variables)) | ||
self.assertEqual(len(project_configs), 3) | ||
|
||
variables = cfgutil.load_config(join(project_dir, 'variables-complex.yaml'), hostname='foo-bar') | ||
project_configs = list(cfgutil.configure_file(config_path, variables)) | ||
self.assertEqual(len(project_configs), 1) | ||
|
||
variables = cfgutil.load_config(join(project_dir, 'variables-complex.yaml'), hostname='foo-foo') | ||
project_configs = list(cfgutil.configure_file(config_path, variables)) | ||
self.assertEqual(len(project_configs), 3) | ||
|
||
def test_configure_string(self): | ||
variables = dict( | ||
foo='foo', | ||
bar=dict( | ||
foo='123', | ||
bar=True, | ||
) | ||
) | ||
self.assertEqual(cfgutil.configure_string('<foo>', variables), 'foo') | ||
self.assertEqual(cfgutil.configure_string('<bar.foo>', variables), '123') | ||
self.assertEqual(cfgutil.configure_string('<bar.foo|s>', variables), '123') | ||
self.assertEqual(cfgutil.configure_string('<bar.foo|i>', variables), 123) | ||
self.assertEqual(cfgutil.configure_string('<bar.foo|f>', variables), 123.0) | ||
self.assertEqual(cfgutil.configure_string('<bar.bar>', variables), 'True') | ||
self.assertEqual(cfgutil.configure_string('<bar.bar|b>', variables), True) | ||
|
||
self.assertIsInstance(cfgutil.configure_string('<bar>', variables), str) | ||
self.assertIsInstance(cfgutil.configure_string('<bar.foo>', variables), str) | ||
self.assertIsInstance(cfgutil.configure_string('<bar.foo|i>', variables), int) | ||
self.assertIsInstance(cfgutil.configure_string('<bar.bar|b>', variables), bool) | ||
|
||
variables = dict( | ||
foo=random.random(), | ||
bar=dict( | ||
foo=random.random(), | ||
) | ||
) | ||
|
||
config = list(cfgutil.configure_file(config_path, variables))[0] | ||
self.assertEqual(config['install'][0]['foo'], variables['foo']) | ||
self.assertEqual(config['install'][0]['bar-foo'], '<bar.foo>') # is not supported |
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,44 @@ | ||
#!/bin/python3 | ||
# author: Jan Hybs | ||
|
||
import tests | ||
|
||
from os.path import join | ||
|
||
from unittest import TestCase | ||
from main import parse_args, main | ||
|
||
project_dir = join(tests.__dir__, 'project-example') | ||
|
||
|
||
class TestProject(TestCase): | ||
|
||
def test_parse_args(self): | ||
with self.assertRaises(SystemExit): | ||
parse_args([]) | ||
|
||
args = [ | ||
'--project=foo', | ||
'--log-path=foo.log', | ||
'--watch-commit-policy=commit-per-day', | ||
'--git-commit=foobar', | ||
'--tty', | ||
] | ||
parsed = parse_args(args) | ||
self.assertEqual(parsed.project, 'foo') | ||
self.assertEqual(parsed.log_path, 'foo.log') | ||
self.assertEqual(parsed.tty, True) | ||
self.assertEqual(parsed.watch_commit_policy, 'commit-per-day') | ||
self.assertListEqual(parsed.step, ['install', 'test']) | ||
self.assertListEqual(parsed.git_commit, ['foobar']) | ||
|
||
# no valid config | ||
with self.assertRaises(SystemExit): | ||
main(args) | ||
|
||
args = [ | ||
'--project=foo', | ||
'--log-level=warning', | ||
'--config-dir=%s' % project_dir, | ||
] | ||
main(args) |
File renamed without changes.
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,36 @@ | ||
#!/bin/python3 | ||
# author: Jan Hybs | ||
|
||
import tests | ||
|
||
import yaml | ||
from os.path import join | ||
from unittest import TestCase | ||
|
||
from cfg.cfgutil import read_file | ||
from vcs.webhooks.push_hook import push_webhook_from_dict, push_webhook_to_dict | ||
|
||
webhook_dir = join(tests.__dir__, 'webhooks') | ||
content = read_file(join(webhook_dir, 'example.json')) | ||
yaml_file = yaml.load(content) | ||
|
||
|
||
class TestPush_webhook(TestCase): | ||
|
||
def test_push_webhook_to_dict(self): | ||
webhook = push_webhook_from_dict(yaml_file) | ||
dictionary = push_webhook_to_dict(webhook) | ||
|
||
self.assertEqual(dictionary['head_commit']['author']['username'], 'janhybs') | ||
self.assertIsInstance(dictionary['commits'], list) | ||
self.assertEqual(dictionary['commits'][0]['timestamp'], '2018-11-19T08:53:54+01:00') | ||
self.assertEqual(dictionary['after'], 'e87eead22e741dafb58355b9a6cbcd632c8f3704') | ||
|
||
def test_push_webhook_from_dict(self): | ||
webhook = push_webhook_from_dict(yaml_file) | ||
|
||
self.assertEqual(webhook.head_commit.author.username, 'janhybs') | ||
self.assertIsInstance(webhook.commits, list) | ||
self.assertEqual(webhook.commits[0].message, 'Change L3 array size from 32 to 44') | ||
self.assertEqual(webhook.commits[0].distinct, True) | ||
self.assertEqual(webhook.after, 'e87eead22e741dafb58355b9a6cbcd632c8f3704') |
File renamed without changes.
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,90 @@ | ||
#!/bin/python3 | ||
# author: Jan Hybs | ||
|
||
import tests | ||
|
||
import time | ||
|
||
import utils.logging | ||
utils.logging.logger.set_level('WARNING') | ||
|
||
|
||
import multiprocessing | ||
from unittest import TestCase | ||
from processing.multi_processing.thread_pool import ( | ||
WorkerPool, Worker, LogStatusFormat | ||
) | ||
|
||
|
||
cpu_count = multiprocessing.cpu_count() | ||
|
||
|
||
class TestWorkerPool(TestCase): | ||
|
||
def test_start_serial(self): | ||
utils.logging.logger.set_level('WARNING') | ||
|
||
items = [dict(foo=123), dict(foo=456)] | ||
processes = 1 | ||
|
||
counter = dict(cnt=0) | ||
|
||
def func(worker: Worker): | ||
counter['cnt'] += 1 | ||
return [counter['cnt'], worker.crate['foo']] | ||
|
||
pool = WorkerPool(items, processes, func) | ||
pool.start_serial() | ||
self.assertListEqual(pool.result, [[1, 123], [2, 456]]) | ||
|
||
def test_start_parallel(self): | ||
utils.logging.logger.set_level('WARNING') | ||
|
||
class A: | ||
def __init__(self, name): | ||
self.name = name | ||
|
||
items = [ | ||
A(name='a'), A(name='b'), A(name='c'), | ||
A(name='a'), A(name='b'), A(name='c'), | ||
A(name='a'), A(name='b'), A(name='c'), | ||
] | ||
result = [[i+1, items[i].name] for i in range(len(items))] | ||
|
||
def func(worker: Worker): | ||
counter['cnt'] += 1 | ||
time.sleep(0.001) | ||
return [counter['cnt'], worker.crate.name] | ||
|
||
# this test is not by its nature bulletproof | ||
# TODO make parallel testing more robust | ||
if cpu_count > 1: | ||
with self.assertRaises(AssertionError): | ||
for i in range(25): | ||
counter = dict(cnt=0) | ||
|
||
pool = WorkerPool(items, 2, func) | ||
pool.log_statuses(format=LogStatusFormat.ONELINE_GROUPED) | ||
pool.start_parallel() | ||
self.assertListEqual(pool.result, result) | ||
|
||
for i in range(10): | ||
counter = dict(cnt=0) | ||
pool = WorkerPool(items, 2, func) | ||
pool.log_statuses(format=LogStatusFormat.COMPLEX) | ||
pool.start_serial() | ||
self.assertListEqual(pool.result, result) | ||
|
||
for i in range(10): | ||
counter = dict(cnt=0) | ||
pool = WorkerPool(items, 1, func) | ||
pool.log_statuses(format=LogStatusFormat.SIMPLE) | ||
pool.start_serial() | ||
self.assertListEqual(pool.result, result) | ||
|
||
for i in range(10): | ||
counter = dict(cnt=0) | ||
pool = WorkerPool(items, 1, func) | ||
pool.log_statuses(format=LogStatusFormat.ONELINE) | ||
pool.start_parallel() | ||
self.assertListEqual(pool.result, result) |
Oops, something went wrong.