scikit-learn / scikit-learn

@@ -1,8 +1,70 @@
Loading
1 1
"""Tests for making sure experimental imports work as expected."""
2 2
3 +
import sys
4 +
import os
5 +
import os.path as op
3 6
import textwrap
7 +
import tempfile
8 +
from subprocess import check_output, STDOUT, CalledProcessError
9 +
from subprocess import TimeoutExpired
4 10
5 -
from sklearn.utils.testing import assert_run_python_script
11 +
12 +
def assert_run_python_script(source_code, timeout=60):
13 +
    """Utility to check assertions in an independent Python subprocess.
14 +
15 +
    The script provided in the source code should return 0 and not print
16 +
    anything on stderr or stdout.
17 +
18 +
    This is a port from cloudpickle https://github.com/cloudpipe/cloudpickle
19 +
20 +
    Parameters
21 +
    ----------
22 +
    source_code : str
23 +
        The Python source code to execute.
24 +
    timeout : int
25 +
        Time in seconds before timeout.
26 +
    """
27 +
    def _make_cwd_env():
28 +
        """Helper to prepare environment for the child processes"""
29 +
        sklearn_repo_folder = op.normpath(
30 +
            op.join(op.dirname(__file__), '../..'))
31 +
        env = os.environ.copy()
32 +
        pythonpath = "{src}{sep}tests{pathsep}{src}".format(
33 +
            src=sklearn_repo_folder, sep=os.sep, pathsep=os.pathsep)
34 +
        env['PYTHONPATH'] = pythonpath
35 +
        return sklearn_repo_folder, env
36 +
37 +
    fd, source_file = tempfile.mkstemp(suffix='_src_test_sklearn.py')
38 +
    os.close(fd)
39 +
    try:
40 +
        with open(source_file, 'wb') as f:
41 +
            f.write(source_code.encode('utf-8'))
42 +
        cmd = [sys.executable, source_file]
43 +
        cwd, env = _make_cwd_env()
44 +
        kwargs = {
45 +
            'cwd': cwd,
46 +
            'stderr': STDOUT,
47 +
            'env': env,
48 +
        }
49 +
        # If coverage is running, pass the config file to the subprocess
50 +
        coverage_rc = os.environ.get("COVERAGE_PROCESS_START")
51 +
        if coverage_rc:
52 +
            kwargs['env']['COVERAGE_PROCESS_START'] = coverage_rc
53 +
54 +
        kwargs['timeout'] = timeout
55 +
        try:
56 +
            try:
57 +
                out = check_output(cmd, **kwargs)
58 +
            except CalledProcessError as e:
59 +
                raise RuntimeError(u"script errored with output:\n%s"
60 +
                                   % e.output.decode('utf-8'))
61 +
            if out != b"":
62 +
                raise AssertionError(out.decode('utf-8'))
63 +
        except TimeoutExpired as e:
64 +
            raise RuntimeError(u"script timeout, output so far:\n%s"
65 +
                               % e.output.decode('utf-8'))
66 +
    finally:
67 +
        os.unlink(source_file)
6 68
7 69
8 70
def test_imports_strategies():

@@ -17,9 +17,6 @@
Loading
17 17
import warnings
18 18
import sys
19 19
import functools
20 -
import tempfile
21 -
from subprocess import check_output, STDOUT, CalledProcessError
22 -
from subprocess import TimeoutExpired
23 20
24 21
25 22
import scipy as sp
@@ -32,7 +29,6 @@
Loading
32 29
33 30
import tempfile
34 31
import shutil
35 -
import os.path as op
36 32
import atexit
37 33
import unittest
38 34
@@ -975,56 +971,3 @@
Loading
975 971
            if n1 != n2:
976 972
                incorrect += [func_name + ' ' + n1 + ' != ' + n2]
977 973
    return incorrect
978 -
979 -
980 -
def assert_run_python_script(source_code, timeout=60):
981 -
    """Utility to check assertions in an independent Python subprocess.
982 -
983 -
    The script provided in the source code should return 0 and not print
984 -
    anything on stderr or stdout.
985 -
986 -
    This is a port from cloudpickle https://github.com/cloudpipe/cloudpickle
987 -
988 -
    Parameters
989 -
    ----------
990 -
    source_code : str
991 -
        The Python source code to execute.
992 -
    timeout : int
993 -
        Time in seconds before timeout.
994 -
    """
995 -
    def _make_cwd_env():
996 -
        """Helper to prepare environment for the child processes"""
997 -
        sklearn_repo_folder = op.normpath(
998 -
            op.join(op.dirname(__file__), '../..'))
999 -
        env = os.environ.copy()
1000 -
        pythonpath = "{src}{sep}tests{pathsep}{src}".format(
1001 -
            src=sklearn_repo_folder, sep=os.sep, pathsep=os.pathsep)
1002 -
        env['PYTHONPATH'] = pythonpath
1003 -
        return sklearn_repo_folder, env
1004 -
1005 -
    fd, source_file = tempfile.mkstemp(suffix='_src_test_sklearn.py')
1006 -
    os.close(fd)
1007 -
    try:
1008 -
        with open(source_file, 'wb') as f:
1009 -
            f.write(source_code.encode('utf-8'))
1010 -
        cmd = [sys.executable, source_file]
1011 -
        cwd, env = _make_cwd_env()
1012 -
        kwargs = {
1013 -
            'cwd': cwd,
1014 -
            'stderr': STDOUT,
1015 -
            'env': env,
1016 -
        }
1017 -
        kwargs['timeout'] = timeout
1018 -
        try:
1019 -
            try:
1020 -
                out = check_output(cmd, **kwargs)
1021 -
            except CalledProcessError as e:
1022 -
                raise RuntimeError(u"script errored with output:\n%s"
1023 -
                                   % e.output.decode('utf-8'))
1024 -
            if out != b"":
1025 -
                raise AssertionError(out.decode('utf-8'))
1026 -
        except TimeoutExpired as e:
1027 -
            raise RuntimeError(u"script timeout, output so far:\n%s"
1028 -
                               % e.output.decode('utf-8'))
1029 -
    finally:
1030 -
        os.unlink(source_file)
Files Coverage
sklearn 96.69%
setup.py 7.02%
Project Totals (384 files) 96.62%
Untitled
Untitled
Untitled
Untitled
1
comment: false
2

3
coverage:
4
  status:
5
    project:
6
      default:
7
        # Commits pushed to master should not make the overall
8
        # project coverage decrease by more than 1%:
9
        target: auto
10
        threshold: 1%
11
    patch:
12
      default:
13
        # Be tolerant on slight code coverage diff on PRs to limit
14
        # noisy red coverage status on github PRs.
15
        # Note The coverage stats are still uploaded
16
        # to codecov so that PR reviewers can see uncovered lines
17
        # in the github diff if they install the codecov browser
18
        # extension:
19
        # https://github.com/codecov/browser-extension
20
        target: auto
21
        threshold: 1%
22

23
ignore:
24
- "sklearn/externals"
Sunburst
The inner-most circle is the entire project, moving away from the center are folders then, finally, a single file. The size and color of each slice is representing the number of statements and the coverage, respectively.
Icicle
The top section represents the entire project. Proceeding with folders and finally individual files. The size and color of each slice is representing the number of statements and the coverage, respectively.
Grid
Each block represents a single file in the project. The size and color of each block is represented by the number of statements and the coverage, respectively.
Loading