Commit 98de40d8 authored by Samuel GAIST's avatar Samuel GAIST
Browse files

Merge branch 'test_updates' into 'master'

Test updates

See merge request !65
parents 13e61714 84bb6277
Pipeline #29597 passed with stages
in 13 minutes and 37 seconds
[flake8]
max-line-length = 80
select = B,C,E,F,W,T4,B9,B950
ignore = E501, W503
# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks
repos:
- repo: https://github.com/ambv/black
rev: stable
hooks:
- id: black
language_version: python3.6
exclude: beat/core/test/prefix/algorithms/user/syntax_error/1.py|beat/core/test/prefix/databases/invalid/1.py
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v2.0.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: debug-statements
exclude: beat/core/test/prefix/algorithms/user/syntax_error/1.py|beat/core/test/prefix/databases/invalid/1.py
- id: check-added-large-files
- id: check-docstring-first
- id: flake8
- id: check-yaml
exclude: conda/meta.yaml
- repo: https://github.com/PyCQA/bandit
rev: 'master' # Update me!
hooks:
- id: bandit
exclude: beat/editor/test|beat/core/test/prefix/algorithms/user/syntax_error/1.py|beat/core/test/prefix/databases/invalid/1.py
- repo: local
hooks:
- id: sphinx-build
name: sphinx build
entry: python -m sphinx.cmd.build
args: [-a, -E, -W, doc, sphinx]
language: system
files: ^doc/
types: [file]
pass_filenames: false
- id: sphinx-doctest
name: sphinx doctest
entry: python -m sphinx.cmd.build
args: [-a, -E, -b, doctest, doc, sphinx]
language: system
files: ^doc/
types: [file]
pass_filenames: false
......@@ -38,47 +38,59 @@
import nose.tools
import click
from click.testing import CliRunner
from . import platform, disconnected, prefix, tmp_prefix, user, token, temp_cwd
from . import platform, disconnected, prefix, tmp_prefix, user, token
from beat.cmdline.scripts import main_cli
from beat.core.test.utils import slow, cleanup, skipif
from beat.core.database import Storage, Database
from beat.backend.python.test.test_database import INTEGERS_DBS
def index_integer_db():
call('index', 'integers_db/1')
call("index", "integers_db/1")
def call(*args, **kwargs):
'''A central mechanism to call the main routine with the right parameters'''
use_prefix = kwargs.get('prefix', prefix)
use_platform = kwargs.get('platform', platform)
runner = CliRunner()
with runner.isolated_filesystem():
result = runner.invoke(
main_cli.main,
['--test-mode', '--prefix', use_prefix, '--token', token,
'--user', user, '--platform', use_platform, 'databases'] +
list(args)
)
if result.exit_code != 0:
click.echo(result.output)
return result.exit_code
"""A central mechanism to call the main routine with the right parameters"""
use_prefix = kwargs.get("prefix", prefix)
use_platform = kwargs.get("platform", platform)
runner = CliRunner()
with runner.isolated_filesystem():
result = runner.invoke(
main_cli.main,
[
"--test-mode",
"--prefix",
use_prefix,
"--token",
token,
"--user",
user,
"--platform",
use_platform,
"databases",
]
+ list(args),
)
if result.exit_code != 0:
click.echo(result.output)
return result.exit_code
@slow
@nose.tools.with_setup(teardown=cleanup)
@skipif(disconnected, "missing test platform (%s)" % platform)
def test_remote_list():
nose.tools.eq_(call('list', '--remote'), 0)
nose.tools.eq_(call("list", "--remote"), 0)
@nose.tools.with_setup(teardown=cleanup)
def test_local_list():
nose.tools.eq_(call('list'), 0)
nose.tools.eq_(call("list"), 0)
@nose.tools.nottest
......@@ -86,10 +98,10 @@ def test_local_list():
@nose.tools.with_setup(teardown=cleanup)
@skipif(disconnected, "missing test platform (%s)" % platform)
def test_pull_one():
obj = 'simple/1'
nose.tools.eq_(call('pull', obj, prefix=tmp_prefix), 0)
s = Storage(tmp_prefix, obj)
assert s.exists()
obj = "simple/1"
nose.tools.eq_(call("pull", obj, prefix=tmp_prefix), 0)
s = Storage(tmp_prefix, obj)
nose.tools.assert_true(s.exists())
@nose.tools.nottest
......@@ -97,84 +109,106 @@ def test_pull_one():
@nose.tools.with_setup(teardown=cleanup)
@skipif(disconnected, "missing test platform (%s)" % platform)
def test_pull_all():
nose.tools.eq_(call('pull', prefix=tmp_prefix), 0)
nose.tools.eq_(call("pull", prefix=tmp_prefix), 0)
@slow
@nose.tools.with_setup(teardown=cleanup)
@skipif(disconnected, "missing test platform (%s)" % platform)
def test_diff():
obj = 'simple/1'
nose.tools.eq_(call('pull', obj, prefix=tmp_prefix), 0)
obj = "simple/1"
nose.tools.eq_(call("pull", obj, prefix=tmp_prefix), 0)
# quickly modify the user algorithm by emptying it
f = Database(tmp_prefix, obj)
nose.tools.eq_(len(f.errors), 0, 'Failed to load Database: \n%s' % '\n'.join(f.errors))
f.data['root_folder'] = '/a/different/path'
f.write()
# quickly modify the user algorithm by emptying it
f = Database(tmp_prefix, obj)
nose.tools.eq_(
len(f.errors), 0, "Failed to load Database: \n%s" % "\n".join(f.errors)
)
f.data["root_folder"] = "/a/different/path"
f.write()
nose.tools.eq_(call('diff', obj, prefix=tmp_prefix), 0)
nose.tools.eq_(call("diff", obj, prefix=tmp_prefix), 0)
@slow
@nose.tools.with_setup(teardown=cleanup)
@skipif(disconnected, "missing test platform (%s)" % platform)
def test_status():
test_diff()
nose.tools.eq_(call('status', prefix=tmp_prefix), 0)
test_diff()
nose.tools.eq_(call("status", prefix=tmp_prefix), 0)
@nose.tools.with_setup(setup=index_integer_db, teardown=cleanup)
def test_view_good():
nose.tools.eq_(call('view', 'integers_db/1/double/double'), 0)
nose.tools.eq_(call("view", "integers_db/1/double/double"), 0)
@nose.tools.with_setup(setup=index_integer_db, teardown=cleanup)
def test_view_unknown_protocol():
nose.tools.eq_(call('view', 'integers_db/1/single/double'), 1)
nose.tools.eq_(call("view", "integers_db/1/single/double"), 1)
@nose.tools.with_setup(setup=index_integer_db, teardown=cleanup)
def test_view_unknown_set():
nose.tools.eq_(call('view', 'integers_db/1/double/single'), 1)
nose.tools.eq_(call("view", "integers_db/1/double/single"), 1)
@nose.tools.with_setup(setup=index_integer_db, teardown=cleanup)
def test_view_bad():
nose.tools.eq_(call('view', 'integers_db/1/two_sets'), 1)
nose.tools.eq_(call("view", "integers_db/1/two_sets"), 1)
@nose.tools.with_setup(setup=index_integer_db, teardown=cleanup)
def test_view_invalid():
nose.tools.eq_(call('view', 'invalid/1/default/set'), 1)
nose.tools.eq_(call("view", "invalid/1/default/set"), 1)
def test_index_unknown_database():
nose.tools.eq_(call('index', 'foobar/1'), 1)
nose.tools.eq_(call("index", "foobar/1"), 1)
@nose.tools.with_setup(teardown=cleanup)
def test_index_good():
nose.tools.eq_(call('index', 'integers_db/1'), 0)
def test_index_method():
for db_name in INTEGERS_DBS:
yield index_good, db_name
@nose.tools.with_setup(teardown=cleanup)
def index_good(db_name):
nose.tools.eq_(call("index", db_name), 0)
def test_list_index_good():
nose.tools.eq_(call('index', 'integers_db/1'), 0)
nose.tools.eq_(call('index', '--list', 'integers_db/1'), 0)
for db_name in INTEGERS_DBS:
yield list_index_good, db_name
@nose.tools.with_setup(teardown=cleanup)
def list_index_good(db_name):
nose.tools.eq_(call("index", db_name), 0)
nose.tools.eq_(call("index", "--list", db_name), 0)
def test_delete_index_good():
nose.tools.eq_(call('index', 'integers_db/1'), 0)
nose.tools.eq_(call('index', '--delete', 'integers_db/1'), 0)
for db_name in INTEGERS_DBS:
yield delete_index_good, db_name
@nose.tools.with_setup(teardown=cleanup)
def delete_index_good(db_name):
nose.tools.eq_(call("index", db_name), 0)
nose.tools.eq_(call("index", "--delete", db_name), 0)
@nose.tools.with_setup(teardown=cleanup)
def test_index_all(): #bad and good, return != 0
expected_errors = 16
existing_errors = call('index')
assert existing_errors >= expected_errors, "There should be at least %d " \
"errors on installed databases, but I've found only %d" % \
(expected_errors, existing_errors)
def test_index_all(): # bad and good, return != 0
expected_errors = 16
existing_errors = call("index")
nose.tools.assert_true(
existing_errors >= expected_errors,
(
"There should be at least %d "
"errors on installed databases, but I've found only %d"
% (expected_errors, existing_errors)
),
)
......@@ -37,12 +37,11 @@
# Basic tests for the command line beat program: experiments
import os
import sys
import logging
import nose.tools
import click
from click.testing import CliRunner
from . import platform, disconnected, prefix, tmp_prefix, user, token, temp_cwd
from . import platform, disconnected, prefix, tmp_prefix, user, token
from .utils import index_experiment_dbs, MockLoggingHandler
from ..common import Selector
from beat.cmdline.scripts import main_cli
......@@ -51,212 +50,227 @@ from beat.core.experiment import Storage, Experiment
def setup_experiments():
index_experiment_dbs('user/user/double_triangle/1/double_triangle')
index_experiment_dbs('user/user/integers_addition/1/integers_addition')
index_experiment_dbs("user/user/double_triangle/1/double_triangle")
index_experiment_dbs("user/user/integers_addition/1/integers_addition")
def call(*args, **kwargs):
'''A central mechanism to call the main routine with the right parameters'''
use_prefix = kwargs.get('prefix', prefix)
use_platform = kwargs.get('platform', platform)
use_cache = kwargs.get('cache', 'cache')
runner = CliRunner()
with runner.isolated_filesystem():
result = runner.invoke(
main_cli.main,
['--test-mode', '--prefix', use_prefix, '--token', token,
'--user', user, '--platform', use_platform, '--cache', use_cache,
'experiments'] +
list(args)
)
if result.exit_code != 0:
click.echo(result.output)
return result.exit_code
"""A central mechanism to call the main routine with the right parameters"""
use_prefix = kwargs.get("prefix", prefix)
use_platform = kwargs.get("platform", platform)
use_cache = kwargs.get("cache", "cache")
runner = CliRunner()
with runner.isolated_filesystem():
result = runner.invoke(
main_cli.main,
[
"--test-mode",
"--prefix",
use_prefix,
"--token",
token,
"--user",
user,
"--platform",
use_platform,
"--cache",
use_cache,
"experiments",
]
+ list(args),
)
if result.exit_code != 0:
click.echo(result.output)
return result.exit_code
@slow
@nose.tools.with_setup(teardown=cleanup)
@skipif(disconnected, "missing test platform (%s)" % platform)
def test_remote_list():
nose.tools.eq_(call('list', '--remote'), 0)
nose.tools.eq_(call("list", "--remote"), 0)
@slow
@nose.tools.with_setup(teardown=cleanup)
@skipif(disconnected, "missing test platform (%s)" % platform)
def test_pull_one(obj=None):
obj = obj or 'user/user/single/1/single'
nose.tools.eq_(call('pull', obj, prefix=tmp_prefix), 0)
s = Storage(tmp_prefix, obj)
assert s.exists()
return s
obj = obj or "user/user/single/1/single"
nose.tools.eq_(call("pull", obj, prefix=tmp_prefix), 0)
s = Storage(tmp_prefix, obj)
nose.tools.assert_true(s.exists())
return s
@slow
@nose.tools.with_setup(teardown=cleanup)
@skipif(disconnected, "missing test platform (%s)" % platform)
def test_pull_all():
nose.tools.eq_(call('pull', prefix=tmp_prefix), 0)
nose.tools.eq_(call("pull", prefix=tmp_prefix), 0)
@slow
@nose.tools.with_setup(teardown=cleanup)
@skipif(disconnected, "missing test platform (%s)" % platform)
def test_diff():
obj = 'user/user/single/1/single'
nose.tools.eq_(call('pull', obj, prefix=tmp_prefix), 0)
obj = "user/user/single/1/single"
nose.tools.eq_(call("pull", obj, prefix=tmp_prefix), 0)
s = Storage(tmp_prefix, obj)
assert s.exists()
s = Storage(tmp_prefix, obj)
nose.tools.assert_true(s.exists())
# quickly modify the user experiment:
f = Experiment(tmp_prefix, obj)
f.data['globals']['queue'] = 'another_queue'
f.write()
# quickly modify the user experiment:
f = Experiment(tmp_prefix, obj)
f.data["globals"]["queue"] = "another_queue"
f.write()
nose.tools.eq_(call('diff', obj, prefix=tmp_prefix), 0)
nose.tools.eq_(call("diff", obj, prefix=tmp_prefix), 0)
@slow
@nose.tools.with_setup(teardown=cleanup)
@skipif(disconnected, "missing test platform (%s)" % platform)
def test_status():
test_diff()
test_pull_one()
nose.tools.eq_(call('status', prefix=tmp_prefix), 0)
test_diff()
test_pull_one()
nose.tools.eq_(call("status", prefix=tmp_prefix), 0)
def test_check_valid():
obj = 'user/user/single/1/single'
nose.tools.eq_(call('check', obj), 0)
obj = "user/user/single/1/single"
nose.tools.eq_(call("check", obj), 0)
def test_check_invalid():
obj = 'user/user/single/1/does_not_exist'
nose.tools.eq_(call('check', obj), 1)
obj = "user/user/single/1/does_not_exist"
nose.tools.eq_(call("check", obj), 1)
@nose.tools.with_setup(teardown=cleanup)
@skipif(disconnected, "missing test platform (%s)" % platform)
def test_fork(obj=None, obj2=None):
obj = obj or 'user/user/single/1/single'
test_pull_one(obj)
obj2 = obj2 or 'user/user/single/1/different'
nose.tools.eq_(call('fork', obj, obj2, prefix=tmp_prefix), 0)
s = Storage(tmp_prefix, obj2)
assert s.exists()
obj = obj or "user/user/single/1/single"
test_pull_one(obj)
obj2 = obj2 or "user/user/single/1/different"
nose.tools.eq_(call("fork", obj, obj2, prefix=tmp_prefix), 0)
s = Storage(tmp_prefix, obj2)
nose.tools.assert_true(s.exists())
# check fork status
with Selector(tmp_prefix) as selector:
assert selector.forked_from('experiment', obj2) == obj
# check fork status
with Selector(tmp_prefix) as selector:
nose.tools.eq_(selector.forked_from("experiment", obj2), obj)
@nose.tools.with_setup(teardown=cleanup)
@skipif(disconnected, "missing test platform (%s)" % platform)
def test_delete_local():
obj = 'user/user/single/1/single'
storage = test_pull_one(obj)
nose.tools.eq_(call('rm', obj, prefix=tmp_prefix), 0)
assert not storage.exists()
obj = "user/user/single/1/single"
storage = test_pull_one(obj)
nose.tools.eq_(call("rm", obj, prefix=tmp_prefix), 0)
nose.tools.assert_false(storage.exists())
@slow
@nose.tools.with_setup(setup=setup_experiments, teardown=cleanup)
def test_run_integers_addition_1():
obj = 'user/user/integers_addition/1/integers_addition'
nose.tools.eq_(call('run', obj, cache=tmp_prefix), 0)
obj = "user/user/integers_addition/1/integers_addition"
nose.tools.eq_(call("run", obj, cache=tmp_prefix), 0)
@slow
@nose.tools.with_setup(setup=setup_experiments, teardown=cleanup)
def test_list_integers_addition_1_cache():
obj = 'user/user/integers_addition/1/integers_addition'
nose.tools.eq_(call('run', obj, cache=tmp_prefix), 0)
nose.tools.eq_(call('caches', '--list', obj, cache=tmp_prefix), 0)
obj = "user/user/integers_addition/1/integers_addition"
nose.tools.eq_(call("run", obj, cache=tmp_prefix), 0)
nose.tools.eq_(call("caches", "--list", obj, cache=tmp_prefix), 0)
@slow
@nose.tools.with_setup(setup=setup_experiments, teardown=cleanup)
def test_checksum_integers_addition_1_cache():
obj = 'user/user/integers_addition/1/integers_addition'
nose.tools.eq_(call('run', obj, cache=tmp_prefix), 0)
nose.tools.eq_(call('caches', '--checksum', obj, cache=tmp_prefix), 0)
obj = "user/user/integers_addition/1/integers_addition"
nose.tools.eq_(call("run", obj, cache=tmp_prefix), 0)
nose.tools.eq_(call("caches", "--checksum", obj, cache=tmp_prefix), 0)
@slow
@nose.tools.with_setup(setup=setup_experiments, teardown=cleanup)
def test_delete_integers_addition_1_cache():
obj = 'user/user/integers_addition/1/integers_addition'
nose.tools.eq_(call('run', obj, cache=tmp_prefix), 0)
nose.tools.eq_(call('caches', '--delete', obj, cache=tmp_prefix), 0)
obj = "user/user/integers_addition/1/integers_addition"
nose.tools.eq_(call("run", obj, cache=tmp_prefix), 0)
nose.tools.eq_(call("caches", "--delete", obj, cache=tmp_prefix), 0)
@slow
@nose.tools.with_setup(setup=setup_experiments, teardown=cleanup)
def test_run_integers_addition_1_twice():
log_handler = MockLoggingHandler(level='DEBUG')
logging.getLogger().addHandler(log_handler)
log_messages = log_handler.messages
log_handler = MockLoggingHandler(level="DEBUG")
logging.getLogger().addHandler(log_handler)
log_messages = log_handler.messages
obj = 'user/user/integers_addition/1/integers_addition'
nose.tools.eq_(call('run', obj, cache=tmp_prefix), 0)
info_len = len(log_messages['info'])
nose.tools.eq_(info_len, 5)
assert log_messages['info'][info_len - 1].startswith(' Results')
nose.tools.eq_(call('run', obj, cache=tmp_prefix), 0)
info_len = len(log_messages['info'])
nose.tools.eq_(info_len, 8)
assert log_messages['info'][info_len - 1].startswith(' Results')
obj = "user/user/integers_addition/1/integers_addition"
nose.tools.eq_(call("run", obj, cache=tmp_prefix), 0)
info_len = len(log_messages["info"])
nose.tools.assert_greater(info_len, 4)
nose.tools.assert_true(log_messages["info"][info_len - 1].startswith(" Results"))
nose.tools.eq_(call("run", obj, cache=tmp_prefix), 0)
info_len = len(log_messages["info"])
nose.tools.assert_greater(info_len, 6)
nose.tools.assert_true(log_messages["info"][info_len - 1].startswith(" Results"))
@slow
@nose.tools.with_setup(setup=setup_experiments, teardown=cleanup)
def test_run_double_triangle_1():
obj = 'user/user/double_triangle/1/double_triangle'
nose.tools.eq_(call('run', obj, cache=tmp_prefix), 0)
obj = "user/user/double_triangle/1/double_triangle"
nose.tools.eq_(call("run", obj, cache=tmp_prefix), 0)
@slow
@nose.tools.with_setup(setup=setup_experiments, teardown=cleanup)
def test_run_single_error_1_local():
# When running locally, the module with the error is loaded
# inside the currently running process and will return '1'.
obj = 'user/user/single/1/single_error'
nose.tools.eq_(call('run', obj, '--local', cache=tmp_prefix), 1)
# When running locally, the module with the error is loaded
# inside the currently running process and will return '1'.
obj = "user/user/single/1/single_error"
nose.tools.eq_(call("run", obj, "--local", cache=tmp_prefix), 1)
@slow
@nose.tools.with_setup(setup=setup_experiments, teardown=cleanup)
def test_run_single_error_twice_local():
# This one makes sure our output reset is working properly. Both tries should
# give out the same error.
obj = 'user/user/single/1/single_error'
nose.tools.eq_(call('run', obj, '--local', cache=tmp_prefix), 1)
nose.tools.eq_(call('run', obj, '--local', cache=tmp_prefix), 1)