Skip to content

Commit 5c8b66a

Browse files
authored
Add python level tests for datascience python files (microsoft#5302)
For #4804 <!-- If an item below does not apply to you, then go ahead and check it off as "done" and strikethrough the text, e.g.: - [x] ~Has unit tests & system/integration tests~ --> - [x] Pull request represents a single change (i.e. not fixing disparate/unrelated things in a single PR) - [x] Title summarizes what is changing - [x] Has a [news entry](https://github.com/Microsoft/vscode-python/tree/master/news) file (remember to thank yourself!) - [ ] Has sufficient logging. - [ ] Has telemetry for enhancements. - [x] Unit tests & system/integration tests are added/updated - [ ] [Test plan](https://github.com/Microsoft/vscode-python/blob/master/.github/test_plan.md) is updated as appropriate - [ ] [`package-lock.json`](https://github.com/Microsoft/vscode-python/blob/master/package-lock.json) has been regenerated by running `npm install` (if dependencies have changed) - [ ] The wiki is updated with any design decisions/details.
1 parent 83b9821 commit 5c8b66a

13 files changed

Lines changed: 6287 additions & 29 deletions

File tree

.vscode/launch.json

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,21 @@
22
{
33
"version": "0.1.0",
44
"configurations": [
5+
{
6+
"name": "Python: Current File with iPython",
7+
"type": "python",
8+
"request": "launch",
9+
"module": "IPython",
10+
"console": "integratedTerminal",
11+
"args": ["${file}"] // Additional args should be prefixed with a '--' first.
12+
},
13+
{
14+
"name": "Python: Current File",
15+
"type": "python",
16+
"request": "launch",
17+
"program": "${file}",
18+
"console": "integratedTerminal"
19+
},
520
{
621
"name": "Extension",
722
"type": "extensionHost",
@@ -179,4 +194,4 @@
179194
]
180195
}
181196
]
182-
}
197+
}

build/ci/templates/test_phases.yml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,21 @@ steps:
172172
displayName: 'pip install functional requirements'
173173
condition: and(succeeded(), eq(variables['NeedsPythonFunctionalReqs'], 'true'))
174174
175+
# Install the requirements for ipython tests.
176+
#
177+
# This task will only run if variable `NeedsIPythonReqs` is true.
178+
#
179+
# Example command line (windows pwsh):
180+
# > python -m pip install numpy
181+
# > python -m pip install --upgrade -r build/ipython-test-requirements.txt
182+
# > python -m pip --disable-pip-version-check install -t ./pythonFiles/lib/python --no-cache-dir --implementation py --no-deps --upgrade -r requirements.txt
183+
- bash: |
184+
python -m pip install -U pip
185+
python -m pip install numpy
186+
python -m pip install --upgrade -r ./build/ipython-test-requirements.txt
187+
displayName: 'pip install ipython requirements'
188+
condition: and(succeeded(), eq(variables['NeedsIPythonReqs'], 'true'))
189+
175190
# Run the Python unit tests in our codebase. Produces a JUnit-style log file that
176191
# will be uploaded after all tests are complete.
177192
#
@@ -197,6 +212,31 @@ steps:
197212
buildPlatform: '$(Agent.Os)-Py$(pythonVersion)'
198213
buildConfiguration: 'UnitTests'
199214

215+
# Run the Python IPython tests in our codebase. Produces a JUnit-style log file that
216+
# will be uploaded after all tests are complete.
217+
#
218+
# This task only runs if the string 'pythonIPythonTests' exists in variable `TestsToRun`.
219+
#
220+
# Example command line (windows pwsh):
221+
# > python -m pip install -m -U pip
222+
# > python -m pip install -U -r build/test-requirements.txt
223+
# > python pythonFiles/tests/run_all.py --color=yes --junit-xml=python-tests-junit.xml
224+
- bash: |
225+
python -m IPython pythonFiles/tests/run_all.py -- --color=yes --junit-xml=$COMMON_TESTRESULTSDIRECTORY/ipython-tests-junit.xml
226+
displayName: 'Python ipython tests'
227+
condition: and(succeeded(), contains(variables['TestsToRun'], 'pythonIPythonTests'))
228+
229+
# Upload the test results to Azure DevOps to facilitate test reporting in their UX.
230+
- task: PublishTestResults@2
231+
displayName: 'Publish IPython test results'
232+
condition: contains(variables['TestsToRun'], 'pythonIPythonTests')
233+
inputs:
234+
testResultsFiles: 'ipython-tests-junit.xml'
235+
searchFolder: '$(Common.TestResultsDirectory)'
236+
testRunTitle: 'pythonIPythonTests-$(Agent.Os)-Py$(pythonVersion)'
237+
buildPlatform: '$(Agent.Os)-Py$(pythonVersion)'
238+
buildConfiguration: 'UnitTests'
239+
200240
# Run the News tool tests.
201241
#
202242
# This task only runs if the string 'pythonInternalTools' exists in variable `TestsToRun`

build/ci/vscode-python-ci.yaml

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ jobs:
3232
# Each member of this list may contain these values:
3333
# NeedsPythonTestReqs: [true|false] - install the test-requirements prior to running tests. False if not set.
3434
# NeedsPythonFunctionalReqs: [true|false] - install the functional-requirements prior to running tests. False if not set.
35+
# NeedsIPythonReqs: [true|false] - install the ipython-test-requirements prior to running tests. False if not set.
3536
# PythonVersion: 'M.m' - the Python version to run. DefaultPythonVersion if not set.
3637
# NodeVersion: 'x.y.z' - Node version to use. DefaultNodeVersion if not set.
3738
# SkipXvfb: [true|false] - skip initialization of xvfb prior to running system tests on Linux. False if not set
@@ -42,70 +43,82 @@ jobs:
4243
'Win-Py3.7 Unit':
4344
PythonVersion: '3.7'
4445
VMImageName: 'vs2017-win2016'
45-
TestsToRun: 'testUnitTests, pythonUnitTests'
46+
TestsToRun: 'testUnitTests, pythonUnitTests, pythonIPythonTests'
4647
NeedsPythonTestReqs: true
48+
NeedsIPythonReqs: true
4749
'Linux-Py3.7 Unit':
4850
PythonVersion: '3.7'
4951
VMImageName: 'ubuntu-16.04'
50-
TestsToRun: 'testUnitTests, pythonUnitTests'
52+
TestsToRun: 'testUnitTests, pythonUnitTests, pythonIPythonTests'
5153
NeedsPythonTestReqs: true
54+
NeedsIPythonReqs: true
5255
'Mac-Py3.7 Unit':
5356
PythonVersion: '3.7'
5457
VMImageName: 'macos-10.13'
55-
TestsToRun: 'testUnitTests, pythonUnitTests'
58+
TestsToRun: 'testUnitTests, pythonUnitTests, pythonIPythonTests'
5659
NeedsPythonTestReqs: true
60+
NeedsIPythonReqs: true
5761
'Win-Py3.6 Unit':
5862
PythonVersion: '3.6'
5963
VMImageName: 'vs2017-win2016'
60-
TestsToRun: 'pythonUnitTests'
64+
TestsToRun: 'pythonUnitTests, pythonIPythonTests'
6165
NeedsPythonTestReqs: true
66+
NeedsIPythonReqs: true
6267
'Linux-Py3.6 Unit':
6368
PythonVersion: '3.6'
6469
VMImageName: 'ubuntu-16.04'
65-
TestsToRun: 'pythonUnitTests'
70+
TestsToRun: 'pythonUnitTests, pythonIPythonTests'
6671
NeedsPythonTestReqs: true
72+
NeedsIPythonReqs: true
6773
'Mac-Py3.6 Unit':
6874
PythonVersion: '3.6'
6975
VMImageName: 'macos-10.13'
70-
TestsToRun: 'pythonUnitTests'
76+
TestsToRun: 'pythonUnitTests, pythonIPythonTests'
7177
NeedsPythonTestReqs: true
78+
NeedsIPythonReqs: true
7279

7380
'Win-Py3.7 Venv':
7481
VMImageName: 'vs2017-win2016'
7582
PythonVersion: '3.7'
76-
TestsToRun: 'venvTests'
83+
TestsToRun: 'venvTests, pythonIPythonTests'
7784
NeedsPythonTestReqs: true
85+
NeedsIPythonReqs: true
7886
# This is for the venvTests to use, not needed if you don't run venv tests...
7987
PYTHON_VIRTUAL_ENVS_LOCATION: './src/tmp/envPaths.json'
8088
'Linux-Py3.7 Venv':
8189
VMImageName: 'ubuntu-16.04'
8290
PythonVersion: '3.7'
83-
TestsToRun: 'venvTests'
91+
TestsToRun: 'venvTests, pythonIPythonTests'
8492
NeedsPythonTestReqs: true
93+
NeedsIPythonReqs: true
8594
PYTHON_VIRTUAL_ENVS_LOCATION: './src/tmp/envPaths.json'
8695
'Mac-Py3.7 Venv':
8796
VMImageName: 'macos-10.13'
8897
PythonVersion: '3.7'
89-
TestsToRun: 'venvTests'
98+
TestsToRun: 'venvTests, pythonIPythonTests'
9099
NeedsPythonTestReqs: true
100+
NeedsIPythonReqs: true
91101
PYTHON_VIRTUAL_ENVS_LOCATION: './src/tmp/envPaths.json'
92102
'Win-Py3.6 Venv':
93103
VMImageName: 'vs2017-win2016'
94104
PythonVersion: '3.6'
95-
TestsToRun: 'venvTests'
105+
TestsToRun: 'venvTests, pythonIPythonTests'
96106
NeedsPythonTestReqs: true
107+
NeedsIPythonReqs: true
97108
PYTHON_VIRTUAL_ENVS_LOCATION: './src/tmp/envPaths.json'
98109
'Linux-Py3.6 Venv':
99110
VMImageName: 'ubuntu-16.04'
100111
PythonVersion: '3.6'
101-
TestsToRun: 'venvTests'
112+
TestsToRun: 'venvTests, pythonIPythonTests'
102113
NeedsPythonTestReqs: true
114+
NeedsIPythonReqs: true
103115
PYTHON_VIRTUAL_ENVS_LOCATION: './src/tmp/envPaths.json'
104116
'Mac-Py3.6 Venv':
105117
VMImageName: 'macos-10.13'
106118
PythonVersion: '3.6'
107-
TestsToRun: 'venvTests'
119+
TestsToRun: 'venvTests, pythonIPythonTests'
108120
NeedsPythonTestReqs: true
121+
NeedsIPythonReqs: true
109122
PYTHON_VIRTUAL_ENVS_LOCATION: './src/tmp/envPaths.json'
110123

111124
# SingleWorkspace Tests
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# List of requirements for ipython tests
2+
numpy
3+
pandas
4+
ipython

news/3 Code Health/4804.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Add tests for variable explorer python files.

pythonFiles/datascience/getJupyterVariableDataFrameInfo.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import pandas as _VSCODE_pd
44

55
# _VSCode_sub_supportsDataExplorer will contain our list of data explorer supported types
6-
_VSCode_supportsDataExplorer = _VSCode_sub_supportsDataExplorer
6+
_VSCode_supportsDataExplorer = "['list', 'Series', 'dict', 'ndarray', 'DataFrame']"
77

88
# In IJupyterVariables.getValue this '_VSCode_JupyterTestValue' will be replaced with the json stringified value of the target variable
99
# Indexes off of _VSCODE_targetVariable need to index types that are part of IJupyterVariable
@@ -58,6 +58,8 @@
5858
_VSCODE_colobj['name'] = _VSCODE_column_name
5959
_VSCODE_colobj['type'] = str(_VSCODE_column_type)
6060
_VSCODE_columns.append(_VSCODE_colobj)
61+
del _VSCODE_column_name
62+
del _VSCODE_column_type
6163

6264
del _VSCODE_columnNames
6365
del _VSCODE_columnTypes

pythonFiles/datascience/getJupyterVariableList.py

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,26 @@
22
# Tested on 2.7 and 3.6
33
from sys import getsizeof as _VSCODE_getsizeof
44
import json as _VSCODE_json
5+
from IPython import get_ipython
56

6-
# _VSCode_sub_supportsDataExplorer will contain our list of data explorer supported types
7-
_VSCode_supportsDataExplorer = _VSCode_sub_supportsDataExplorer
7+
# _VSCode_supportsDataExplorer will contain our list of data explorer supported types
8+
_VSCode_supportsDataExplorer = "['list', 'Series', 'dict', 'ndarray', 'DataFrame']"
89

910
# who_ls is a Jupyter line magic to fetch currently defined vars
10-
_VSCode_JupyterVars = %who_ls
11+
_VSCode_JupyterVars = get_ipython().run_line_magic('who_ls', '')
1112

12-
print(_VSCODE_json.dumps([{'name': var,
13-
'type': type(eval(var)).__name__,
14-
'size': _VSCODE_getsizeof(var),
15-
'supportsDataExplorer': type(eval(var)).__name__ in _VSCode_supportsDataExplorer
16-
} for var in _VSCode_JupyterVars]))
13+
_VSCode_output = []
14+
for var in _VSCode_JupyterVars:
15+
try:
16+
_VSCode_type = type(eval(var))
17+
_VSCode_output.append({'name': var, 'type': _VSCode_type.__name__, 'size': _VSCODE_getsizeof(var), 'supportsDataExplorer': _VSCode_type.__name__ in _VSCode_supportsDataExplorer })
18+
del _VSCode_type
19+
except:
20+
pass
1721

22+
print(_VSCODE_json.dumps(_VSCode_output))
23+
24+
del _VSCode_output
1825
del _VSCode_supportsDataExplorer
1926
del _VSCode_JupyterVars
2027
del _VSCODE_json

pythonFiles/tests/__main__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
TEST_ROOT = os.path.dirname(__file__)
1212
SRC_ROOT = os.path.dirname(TEST_ROOT)
1313
PROJECT_ROOT = os.path.dirname(SRC_ROOT)
14-
DATASCIENCE_ROOT = os.path.join(SRC_ROOT, 'datascience')
14+
IPYTHON_ROOT = os.path.join(SRC_ROOT, 'ipython')
1515
TESTING_TOOLS_ROOT = os.path.join(SRC_ROOT, 'testing_tools')
1616

1717

@@ -30,7 +30,7 @@ def parse_args():
3030

3131

3232
def main(pytestargs, markers=None):
33-
sys.path.insert(1, DATASCIENCE_ROOT)
33+
sys.path.insert(1, IPYTHON_ROOT)
3434
sys.path.insert(1, TESTING_TOOLS_ROOT)
3535

3636
pytestargs = [

0 commit comments

Comments
 (0)