test_databases.py 5.4 KB
Newer Older
André Anjos's avatar
André Anjos committed
1
2
#!/usr/bin/env python
# vim: set fileencoding=utf-8 :
André Anjos's avatar
André Anjos committed
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162

###############################################################################
#                                                                             #
# Copyright (c) 2016 Idiap Research Institute, http://www.idiap.ch/           #
# Contact: beat.support@idiap.ch                                              #
#                                                                             #
# This file is part of the beat.cmdline module of the BEAT platform.          #
#                                                                             #
# Commercial License Usage                                                    #
# Licensees holding valid commercial BEAT licenses may use this file in       #
# accordance with the terms contained in a written agreement between you      #
# and Idiap. For further information contact tto@idiap.ch                     #
#                                                                             #
# Alternatively, this file may be used under the terms of the GNU Affero      #
# Public License version 3 as published by the Free Software and appearing    #
# in the file LICENSE.AGPL included in the packaging of this file.            #
# The BEAT platform is distributed in the hope that it will be useful, but    #
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY  #
# or FITNESS FOR A PARTICULAR PURPOSE.                                        #
#                                                                             #
# You should have received a copy of the GNU Affero Public License along      #
# with the BEAT platform. If not, see http://www.gnu.org/licenses/.           #
#                                                                             #
###############################################################################


# Basic tests for the command line beat program: databases

import nose.tools

from . import platform, disconnected, prefix, tmp_prefix, user, token
from ..scripts.beat import main
from beat.core.test.utils import slow, cleanup, skipif
from beat.core.database import Storage, Database


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)

  return main((
      '--platform=%s' % use_platform,
      '--user=%s' % user,
      '--token=%s' % token,
      '--prefix=%s' % use_prefix,
      '--test-mode',
      'database',
      ) + args)


@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.with_setup(teardown=cleanup)
def test_local_list():
  nose.tools.eq_(call('list'), 0)


@nose.tools.nottest
@slow
@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()


@nose.tools.nottest
@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)


@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)

  # quickly modify the user algorithm by emptying it
  f = Database(tmp_prefix, obj)
  f.data['root_folder'] = '/a/different/path'
  f.write()

  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)


def test_view_good():
  nose.tools.eq_(call('view', 'integers_db/1/double/double'), 0)


def test_view_unknown_protocol():
  nose.tools.eq_(call('view', 'integers_db/1/single/double'), 1)


def test_view_unknown_set():
  nose.tools.eq_(call('view', 'integers_db/1/double/single'), 1)


def test_view_bad():
  nose.tools.eq_(call('view', 'integers_db/1/double'), 1)


def test_view_invalid():
  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.with_setup(teardown=cleanup)
def test_index_good():
  nose.tools.eq_(call('index', 'integers_db/1'), 0)


@nose.tools.with_setup(teardown=cleanup)
def test_list_index_good():
  nose.tools.eq_(call('index', 'integers_db/1'), 0)
  nose.tools.eq_(call('index', '--list', 'integers_db/1'), 0)


@nose.tools.with_setup(teardown=cleanup)
def test_checksum_index_good():
  nose.tools.eq_(call('index', 'integers_db/1'), 0)
  nose.tools.eq_(call('index', '--checksum', 'integers_db/1'), 0)


@nose.tools.with_setup(teardown=cleanup)
def test_delete_index_good():
  nose.tools.eq_(call('index', 'integers_db/1'), 0)
  nose.tools.eq_(call('index', '--delete', 'integers_db/1'), 0)


@nose.tools.with_setup(teardown=cleanup)
def test_index_all(): #bad and good, return != 0
  expected_errors = 19
  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)