File: test_pydevcoverage.py

package info (click to toggle)
pydevd 3.3.0%2Bds-4
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 13,892 kB
  • sloc: python: 77,508; cpp: 1,869; sh: 368; makefile: 50; ansic: 4
file content (63 lines) | stat: -rw-r--r-- 2,453 bytes parent folder | download | duplicates (2)
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
import os
import re
import sys
import subprocess
import tempfile
import unittest


# =======================================================================================================================
# Test
# =======================================================================================================================
class Test(unittest.TestCase):
    """
    Unittest for pydev_coverage.py.
    TODO:
      - 'combine' in arguments
      - no 'combine' and no 'pydev-analyze' in arguments
    """

    def setUp(self):
        unittest.TestCase.setUp(self)
        project_path = os.path.dirname(os.path.dirname(__file__))
        self._resources_path = os.path.join(project_path, "tests_python", "resources")
        self._coverage_file = os.path.join(project_path, "pydev_coverage.py")

    def _do_analyze(self, files):
        invalid_files = []

        p = subprocess.Popen(
            [sys.executable, self._coverage_file, "--pydev-analyze"], stdout=subprocess.PIPE, stdin=subprocess.PIPE, stderr=subprocess.PIPE
        )
        __, stderrdata = p.communicate("|".join(files).encode())

        if stderrdata:
            match = re.search("Invalid files not passed to coverage: (.*?)$", stderrdata.decode(), re.M)  # @UndefinedVariable
            if match:
                invalid_files = [f.strip() for f in match.group(1).split(",")]
        return invalid_files

    def test_pydev_analyze_ok(self):
        ref_valid_files = [__file__, os.path.join(self._resources_path, "_debugger_case18.py")]
        ref_invalid_files = []

        invalid_files = self._do_analyze(ref_valid_files)

        self.assertEqual(ref_invalid_files, invalid_files)

    def test_pydev_analyse_non_standard_encoding(self):
        ref_valid_files = [os.path.join(self._resources_path, "_pydev_coverage_cyrillic_encoding_py%i.py" % sys.version_info[0])]
        ref_invalid_files = []

        invalid_files = self._do_analyze(ref_valid_files + ref_invalid_files)

        self.assertEqual(ref_invalid_files, invalid_files)

    def test_pydev_analyse_invalid_files(self):
        with tempfile.NamedTemporaryFile(suffix=".pyx") as pyx_file:
            ref_valid_files = []
            ref_invalid_files = [os.path.join(self._resources_path, "_pydev_coverage_syntax_error.py"), pyx_file.name]

            invalid_files = self._do_analyze(ref_valid_files + ref_invalid_files)

            self.assertEqual(ref_invalid_files, invalid_files)