forked from fabioz/PyDev.Debugger
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_pydevcoverage.py
More file actions
63 lines (48 loc) · 2.4 KB
/
Copy pathtest_pydevcoverage.py
File metadata and controls
63 lines (48 loc) · 2.4 KB
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)