Move tests to a standard location

Related to #10385570

authorPhilippe Pepiot <philippe.pepiot@logilab.fr>
changeset89e0c9b066e8
branchdefault
phasepublic
hiddenno
parent revision#78670ce3bf65 Added tag 0.1.0, debian/0.1.0-1 for changeset 90757c1084e4
child revision#3320736b6a36 [pkg] add project url on cubicweb forge
files modified by this revision
MANIFEST.in
cubes/celery/test/data/bootstrap_cubes
cubes/celery/test/data/celeryconfig.py
cubes/celery/test/data/sobjects.py
cubes/celery/test/test_celery.py
cwcelerytest/__init__.py
cwcelerytest/__pkginfo__.py
cwcelerytest/setup.py
cwcelerytest/sobjects.py
cwcelerytest/tasks.py
cwcelerytest/test/data/bootstrap_cubes
cwcelerytest/test/data/celeryconfig.py
cwcelerytest/test/test_celerytest.py
# HG changeset patch
# User Philippe Pepiot <philippe.pepiot@logilab.fr>
# Date 1472732770 -7200
# Thu Sep 01 14:26:10 2016 +0200
# Node ID 89e0c9b066e874f696d219e9363726a69b8d1717
# Parent 78670ce3bf657a47e7aa60d9bbf49ab8adff88bd
Move tests to a standard location

Related to #10385570

diff --git a/MANIFEST.in b/MANIFEST.in
@@ -1,3 +1,1 @@
1  recursive-include cubes/celery *.py
2 -recursive-include cwcelerytest *.py
3 -recursive-include cwcelerytest bootstrap_cubes
diff --git a/cubes/celery/test/data/bootstrap_cubes b/cubes/celery/test/data/bootstrap_cubes
@@ -0,0 +1,1 @@
4 +celery
diff --git a/cubes/celery/test/data/celeryconfig.py b/cubes/celery/test/data/celeryconfig.py
@@ -0,0 +1,1 @@
5 +CELERY_TIMEZONE = 'Indian/Maldives'
diff --git a/cubes/celery/test/data/sobjects.py b/cubes/celery/test/data/sobjects.py
@@ -0,0 +1,6 @@
6 +from cubicweb_celery import app
7 +
8 +
9 +@app.cwtask(name='newgroup')
10 +def newgroup(self, name):
11 +    return self.cw_cnx.create_entity('CWGroup', name=name).eid
diff --git a/cubes/celery/test/test_celery.py b/cubes/celery/test/test_celery.py
@@ -0,0 +1,40 @@
12 +# copyright 2016 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
13 +# contact http://www.logilab.fr -- mailto:contact@logilab.fr
14 +#
15 +# This program is free software: you can redistribute it and/or modify it under
16 +# the terms of the GNU Lesser General Public License as published by the Free
17 +# Software Foundation, either version 2.1 of the License, or (at your option)
18 +# any later version.
19 +#
20 +# This program is distributed in the hope that it will be useful, but WITHOUT
21 +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
22 +# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
23 +# details.
24 +#
25 +# You should have received a copy of the GNU Lesser General Public License
26 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
27 +
28 +
29 +from cubicweb.devtools import testlib
30 +from cubicweb_celery import app, init_repo
31 +
32 +
33 +class DefaultTC(testlib.CubicWebTC):
34 +    def setUp(self):
35 +        super(DefaultTC, self).setUp()
36 +        app.cwrepo = init_repo(app.cwconfig)
37 +
38 +    def test_cwtask(self):
39 +        eid = app.tasks['newgroup'](u'test')
40 +        with self.admin_access.repo_cnx() as cnx:
41 +            self.assertEqual(cnx.entity_from_eid(eid).name, u'test')
42 +
43 +    def test_default_config(self):
44 +        self.assertTrue(app.conf.CELERY_ENABLE_UTC)
45 +        self.assertEqual('Indian/Maldives',
46 +                         app.conf.CELERY_TIMEZONE)
47 +
48 +
49 +if __name__ == '__main__':
50 +    from logilab.common.testlib import unittest_main
51 +    unittest_main()
diff --git a/cwcelerytest/__init__.py b/cwcelerytest/__init__.py
@@ -1,6 +0,0 @@
52 -"""cubicweb-celerytest application package
53 -
54 -Celery Test cube
55 -"""
56 -
57 -import tasks  # noqa
diff --git a/cwcelerytest/__pkginfo__.py b/cwcelerytest/__pkginfo__.py
@@ -1,50 +0,0 @@
58 -# pylint: disable=W0622
59 -"""cubicweb-celerytest application packaging information"""
60 -
61 -modname = 'cwcelerytest'
62 -distname = 'cubicweb-cwcelerytest'
63 -
64 -numversion = (0, 1, 0)
65 -version = '.'.join(str(num) for num in numversion)
66 -
67 -license = 'LGPL'
68 -author = 'LOGILAB S.A. (Paris, FRANCE)'
69 -author_email = 'contact@logilab.fr'
70 -description = 'Celery Test cube'
71 -web = 'http://www.cubicweb.org/project/%s' % distname
72 -
73 -__depends__ =  {'cubicweb': '>= 3.19.6',
74 -                'cubicweb-celery': None,
75 -                }
76 -__recommends__ = {}
77 -
78 -classifiers = [
79 -    'Environment :: Web Environment',
80 -    'Framework :: CubicWeb',
81 -    'Programming Language :: Python',
82 -    'Programming Language :: JavaScript',
83 -    ]
84 -
85 -from os import listdir as _listdir
86 -from os.path import join, isdir
87 -from glob import glob
88 -
89 -THIS_CUBE_DIR = join('share', 'cubicweb', 'cubes', modname)
90 -
91 -def listdir(dirpath):
92 -    return [join(dirpath, fname) for fname in _listdir(dirpath)
93 -            if fname[0] != '.' and not fname.endswith('.pyc')
94 -            and not fname.endswith('~')
95 -            and not isdir(join(dirpath, fname))]
96 -
97 -data_files = [
98 -    # common files
99 -    [THIS_CUBE_DIR, [fname for fname in glob('*.py') if fname != 'setup.py']],
100 -    ]
101 -# check for possible extended cube layout
102 -for dname in ('entities', 'views', 'sobjects', 'hooks', 'schema', 'data', 'wdoc', 'i18n', 'migration'):
103 -    if isdir(dname):
104 -        data_files.append([join(THIS_CUBE_DIR, dname), listdir(dname)])
105 -# Note: here, you'll need to add subdirectories if you want
106 -# them to be included in the debian package
107 -
diff --git a/cwcelerytest/setup.py b/cwcelerytest/setup.py
@@ -1,201 +0,0 @@
108 -#!/usr/bin/env python
109 -# pylint: disable=W0142,W0403,W0404,W0613,W0622,W0622,W0704,R0904,C0103,E0611
110 -#
111 -# copyright 2003-2010 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
112 -# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
113 -#
114 -# This file is part of CubicWeb tag cube.
115 -#
116 -# CubicWeb is free software: you can redistribute it and/or modify it under the
117 -# terms of the GNU Lesser General Public License as published by the Free
118 -# Software Foundation, either version 2.1 of the License, or (at your option)
119 -# any later version.
120 -#
121 -# CubicWeb is distributed in the hope that it will be useful, but WITHOUT
122 -# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
123 -# FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
124 -# details.
125 -#
126 -# You should have received a copy of the GNU Lesser General Public License along
127 -# with CubicWeb.  If not, see <http://www.gnu.org/licenses/>.
128 -"""Generic Setup script, takes package info from __pkginfo__.py file
129 -"""
130 -__docformat__ = "restructuredtext en"
131 -
132 -import os
133 -import sys
134 -import shutil
135 -from os.path import isdir, exists, join, walk
136 -
137 -try:
138 -    if os.environ.get('NO_SETUPTOOLS'):
139 -        raise ImportError() # do as there is no setuptools
140 -    from setuptools import setup
141 -    from setuptools.command import install_lib
142 -    USE_SETUPTOOLS = True
143 -except ImportError:
144 -    from distutils.core import setup
145 -    from distutils.command import install_lib
146 -    USE_SETUPTOOLS = False
147 -from distutils.command import install_data
148 -
149 -# import required features
150 -from __pkginfo__ import modname, version, license, description, web, \
151 -     author, author_email, classifiers
152 -
153 -if exists('README'):
154 -    long_description = file('README').read()
155 -else:
156 -    long_description = ''
157 -
158 -# import optional features
159 -import __pkginfo__
160 -if USE_SETUPTOOLS:
161 -    requires = {}
162 -    for entry in ("__depends__",): # "__recommends__"):
163 -        requires.update(getattr(__pkginfo__, entry, {}))
164 -    install_requires = [("%s %s" % (d, v and v or "")).strip()
165 -                       for d, v in requires.iteritems()]
166 -else:
167 -    install_requires = []
168 -
169 -distname = getattr(__pkginfo__, 'distname', modname)
170 -scripts = getattr(__pkginfo__, 'scripts', ())
171 -include_dirs = getattr(__pkginfo__, 'include_dirs', ())
172 -data_files = getattr(__pkginfo__, 'data_files', None)
173 -ext_modules = getattr(__pkginfo__, 'ext_modules', None)
174 -dependency_links = getattr(__pkginfo__, 'dependency_links', ())
175 -
176 -BASE_BLACKLIST = ('CVS', '.svn', '.hg', 'debian', 'dist', 'build')
177 -IGNORED_EXTENSIONS = ('.pyc', '.pyo', '.elc', '~')
178 -
179 -
180 -def ensure_scripts(linux_scripts):
181 -    """
182 -    Creates the proper script names required for each platform
183 -    (taken from 4Suite)
184 -    """
185 -    from distutils import util
186 -    if util.get_platform()[:3] == 'win':
187 -        scripts_ = [script + '.bat' for script in linux_scripts]
188 -    else:
189 -        scripts_ = linux_scripts
190 -    return scripts_
191 -
192 -def export(from_dir, to_dir,
193 -           blacklist=BASE_BLACKLIST,
194 -           ignore_ext=IGNORED_EXTENSIONS,
195 -           verbose=True):
196 -    """make a mirror of from_dir in to_dir, omitting directories and files
197 -    listed in the black list
198 -    """
199 -    def make_mirror(arg, directory, fnames):
200 -        """walk handler"""
201 -        for norecurs in blacklist:
202 -            try:
203 -                fnames.remove(norecurs)
204 -            except ValueError:
205 -                pass
206 -        for filename in fnames:
207 -            # don't include binary files
208 -            if filename[-4:] in ignore_ext:
209 -                continue
210 -            if filename[-1] == '~':
211 -                continue
212 -            src = join(directory, filename)
213 -            dest = to_dir + src[len(from_dir):]
214 -            if verbose:
215 -                sys.stderr.write('%s -> %s\n' % (src, dest))
216 -            if os.path.isdir(src):
217 -                if not exists(dest):
218 -                    os.mkdir(dest)
219 -            else:
220 -                if exists(dest):
221 -                    os.remove(dest)
222 -                shutil.copy2(src, dest)
223 -    try:
224 -        os.mkdir(to_dir)
225 -    except OSError as ex:
226 -        # file exists ?
227 -        import errno
228 -        if ex.errno != errno.EEXIST:
229 -            raise
230 -    walk(from_dir, make_mirror, None)
231 -
232 -
233 -class MyInstallLib(install_lib.install_lib):
234 -    """extend install_lib command to handle  package __init__.py and
235 -    include_dirs variable if necessary
236 -    """
237 -    def run(self):
238 -        """overridden from install_lib class"""
239 -        install_lib.install_lib.run(self)
240 -        # manually install included directories if any
241 -        if include_dirs:
242 -            base = modname
243 -            for directory in include_dirs:
244 -                dest = join(self.install_dir, base, directory)
245 -                export(directory, dest, verbose=False)
246 -
247 -# re-enable copying data files in sys.prefix
248 -old_install_data = install_data.install_data
249 -if USE_SETUPTOOLS:
250 -    # overwrite InstallData to use sys.prefix instead of the egg directory
251 -    class MyInstallData(old_install_data):
252 -        """A class that manages data files installation"""
253 -        def run(self):
254 -            _old_install_dir = self.install_dir
255 -            if self.install_dir.endswith('egg'):
256 -                self.install_dir = sys.prefix
257 -            old_install_data.run(self)
258 -            self.install_dir = _old_install_dir
259 -    try:
260 -        import setuptools.command.easy_install # only if easy_install available
261 -        # monkey patch: Crack SandboxViolation verification
262 -        from setuptools.sandbox import DirectorySandbox as DS
263 -        old_ok = DS._ok
264 -        def _ok(self, path):
265 -            """Return True if ``path`` can be written during installation."""
266 -            out = old_ok(self, path) # here for side effect from setuptools
267 -            realpath = os.path.normcase(os.path.realpath(path))
268 -            allowed_path = os.path.normcase(sys.prefix)
269 -            if realpath.startswith(allowed_path):
270 -                out = True
271 -            return out
272 -        DS._ok = _ok
273 -    except ImportError:
274 -        pass
275 -
276 -def install(**kwargs):
277 -    """setup entry point"""
278 -    if USE_SETUPTOOLS:
279 -        if '--force-manifest' in sys.argv:
280 -            sys.argv.remove('--force-manifest')
281 -    # install-layout option was introduced in 2.5.3-1~exp1
282 -    elif sys.version_info < (2, 5, 4) and '--install-layout=deb' in sys.argv:
283 -        sys.argv.remove('--install-layout=deb')
284 -    cmdclass = {'install_lib': MyInstallLib}
285 -    if USE_SETUPTOOLS:
286 -        kwargs['install_requires'] = install_requires
287 -        kwargs['dependency_links'] = dependency_links
288 -        kwargs['zip_safe'] = False
289 -        cmdclass['install_data'] = MyInstallData
290 -
291 -    return setup(name = distname,
292 -                 version = version,
293 -                 license = license,
294 -                 description = description,
295 -                 long_description = long_description,
296 -                 author = author,
297 -                 author_email = author_email,
298 -                 url = web,
299 -                 scripts = ensure_scripts(scripts),
300 -                 data_files = data_files,
301 -                 ext_modules = ext_modules,
302 -                 cmdclass = cmdclass,
303 -                 classifiers = classifiers,
304 -                 **kwargs
305 -                 )
306 -
307 -if __name__ == '__main__' :
308 -    install()
diff --git a/cwcelerytest/sobjects.py b/cwcelerytest/sobjects.py
diff --git a/cwcelerytest/tasks.py b/cwcelerytest/tasks.py
@@ -1,14 +0,0 @@
309 -from cubicweb_celery import app
310 -
311 -
312 -@app.cwtask
313 -def newgroup(self, name):
314 -    return self.cw_cnx.create_entity('CWGroup', name=name).eid
315 -
316 -
317 -@app.cwtask
318 -def newgroup_retried(self, name):
319 -    try:
320 -        1 / 0
321 -    except Exception as ex:
322 -        self.retry(ex, countdown=5)
diff --git a/cwcelerytest/test/data/bootstrap_cubes b/cwcelerytest/test/data/bootstrap_cubes
@@ -1,1 +0,0 @@
323 -cwcelerytest
diff --git a/cwcelerytest/test/data/celeryconfig.py b/cwcelerytest/test/data/celeryconfig.py
@@ -1,1 +0,0 @@
324 -CELERY_TIMEZONE = 'Indian/Maldives'
diff --git a/cwcelerytest/test/test_celerytest.py b/cwcelerytest/test/test_celerytest.py
@@ -1,41 +0,0 @@
325 -# copyright 2015 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
326 -# contact http://www.logilab.fr -- mailto:contact@logilab.fr
327 -#
328 -# This program is free software: you can redistribute it and/or modify it under
329 -# the terms of the GNU Lesser General Public License as published by the Free
330 -# Software Foundation, either version 2.1 of the License, or (at your option)
331 -# any later version.
332 -#
333 -# This program is distributed in the hope that it will be useful, but WITHOUT
334 -# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
335 -# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
336 -# details.
337 -#
338 -# You should have received a copy of the GNU Lesser General Public License along
339 -# with this program. If not, see <http://www.gnu.org/licenses/>.
340 -
341 -
342 -from cubicweb.devtools import testlib
343 -from cubes.cwcelerytest import tasks
344 -from cubicweb_celery import app, init_repo
345 -
346 -
347 -class DefaultTC(testlib.CubicWebTC):
348 -    def setUp(self):
349 -        super(DefaultTC, self).setUp()
350 -        app.cwrepo = init_repo(app.cwconfig)
351 -
352 -    def test_cwtask(self):
353 -        eid = tasks.newgroup(u'test')
354 -        with self.admin_access.repo_cnx() as cnx:
355 -            self.assertEqual(cnx.entity_from_eid(eid).name, u'test')
356 -
357 -    def test_default_config(self):
358 -        self.assertTrue(app.conf.CELERY_ENABLE_UTC)
359 -        self.assertEqual('Indian/Maldives',
360 -                         app.conf.CELERY_TIMEZONE)
361 -
362 -
363 -if __name__ == '__main__':
364 -    from logilab.common.testlib import unittest_main
365 -    unittest_main()