File: __init__.py

package info (click to toggle)
python-astropy-helpers 1.3-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 756 kB
  • ctags: 698
  • sloc: python: 5,929; ansic: 88; makefile: 11
file content (70 lines) | stat: -rw-r--r-- 1,817 bytes parent folder | download | duplicates (17)
1
2
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
import os
import subprocess as sp
import sys

from textwrap import dedent

import pytest


@pytest.fixture
def cython_testpackage(tmpdir, request):
    """
    Creates a trivial Cython package for use with tests.
    """

    test_pkg = tmpdir.mkdir('test_pkg')
    test_pkg.mkdir('apyhtest_eva').ensure('__init__.py')
    test_pkg.join('apyhtest_eva').join('unit02.pyx').write(dedent("""\
        def pilot():
            \"\"\"Returns the pilot of Eva Unit-02.\"\"\"

            return True
    """))

    import astropy_helpers

    test_pkg.join('setup.py').write(dedent("""\
        import sys

        sys.path.insert(0, {0!r})

        from os.path import join
        from setuptools import setup, Extension
        from astropy_helpers.setup_helpers import register_commands

        NAME = 'apyhtest_eva'
        VERSION = 0.1
        RELEASE = True

        cmdclassd = register_commands(NAME, VERSION, RELEASE)

        setup(
            name=NAME,
            version=VERSION,
            cmdclass=cmdclassd,
            ext_modules=[Extension('apyhtest_eva.unit02',
                                   [join('apyhtest_eva', 'unit02.pyx')])]
        )
    """.format(os.path.dirname(astropy_helpers.__path__[0]))))

    test_pkg.chdir()
    # Build the Cython module in a subprocess; otherwise strange things can
    # happen with Cython's global module state
    sp.call([sys.executable, 'setup.py', 'build_ext', '--inplace'])

    sys.path.insert(0, str(test_pkg))
    import apyhtest_eva.unit02

    def cleanup(test_pkg=test_pkg):
        for modname in ['apyhtest_eva', 'apyhtest_eva.unit02']:
            try:
                del sys.modules[modname]
            except KeyError:
                pass

        sys.path.remove(str(test_pkg))

    request.addfinalizer(cleanup)

    return test_pkg