@@ -5,7 +5,7 @@ import { window } from 'vscode'
55import { Disposable } from '../../../extension'
66import * as PythonExtension from '../../../extensions/python'
77import * as Python from '../../../python'
8- import { autoInstallDvc } from '../../../setup/autoInstall'
8+ import { autoInstallDvc , autoUpgradeDvc } from '../../../setup/autoInstall'
99import * as WorkspaceFolders from '../../../vscode/workspaceFolders'
1010import { bypassProgressCloseDelay } from '../util'
1111import { Toast } from '../../../vscode/toast'
@@ -23,9 +23,98 @@ suite('Auto Install Test Suite', () => {
2323 disposable . dispose ( )
2424 } )
2525
26- describe ( 'autoInstallDvc' , ( ) => {
27- const defaultPython = getDefaultPython ( )
26+ const defaultPython = getDefaultPython ( )
27+
28+ describe ( 'autoUpgradeDvc' , ( ) => {
29+ it ( 'should return early if no Python interpreter is found' , async ( ) => {
30+ stub ( PythonExtension , 'getPythonExecutionDetails' ) . resolves ( undefined )
31+ stub ( Python , 'findPythonBin' ) . resolves ( undefined )
32+ const mockInstallPackages = stub ( Python , 'installPackages' ) . resolves (
33+ undefined
34+ )
35+
36+ const showProgressSpy = spy ( window , 'withProgress' )
37+ const showErrorSpy = spy ( window , 'showErrorMessage' )
38+
39+ await autoUpgradeDvc ( )
40+
41+ expect ( showProgressSpy ) . not . to . be . called
42+ expect ( showErrorSpy ) . to . be . called
43+ expect ( mockInstallPackages ) . not . to . be . called
44+ } )
45+
46+ it ( 'should return early if there is no workspace folder open' , async ( ) => {
47+ stub ( PythonExtension , 'getPythonExecutionDetails' ) . resolves ( undefined )
48+ stub ( Python , 'findPythonBin' ) . resolves ( defaultPython )
49+ const mockInstallPackages = stub ( Python , 'installPackages' ) . resolves (
50+ undefined
51+ )
52+ stub ( WorkspaceFolders , 'getFirstWorkspaceFolder' ) . returns ( undefined )
2853
54+ const showProgressSpy = spy ( window , 'withProgress' )
55+ const showErrorSpy = spy ( window , 'showErrorMessage' )
56+
57+ await autoUpgradeDvc ( )
58+
59+ expect ( showProgressSpy ) . not . to . be . called
60+ expect ( showErrorSpy ) . to . be . called
61+ expect ( mockInstallPackages ) . not . to . be . called
62+ } )
63+
64+ it ( 'should install DVC if a Python interpreter is found' , async ( ) => {
65+ bypassProgressCloseDelay ( )
66+ const cwd = __dirname
67+ stub ( PythonExtension , 'getPythonExecutionDetails' ) . resolves ( undefined )
68+ stub ( Python , 'findPythonBin' ) . resolves ( defaultPython )
69+ const mockInstallPackages = stub ( Python , 'installPackages' ) . resolves (
70+ undefined
71+ )
72+ stub ( WorkspaceFolders , 'getFirstWorkspaceFolder' ) . returns ( cwd )
73+
74+ const showProgressSpy = spy ( window , 'withProgress' )
75+ const showErrorSpy = spy ( window , 'showErrorMessage' )
76+
77+ await autoUpgradeDvc ( )
78+
79+ expect ( showProgressSpy ) . to . be . called
80+ expect ( showErrorSpy ) . not . to . be . called
81+ expect ( mockInstallPackages ) . to . be . called
82+ expect ( mockInstallPackages ) . to . be . calledWithExactly (
83+ cwd ,
84+ defaultPython ,
85+ 'dvc'
86+ )
87+ } )
88+
89+ it ( 'should show an error message if DVC fails to install' , async ( ) => {
90+ bypassProgressCloseDelay ( )
91+ const cwd = __dirname
92+ stub ( PythonExtension , 'getPythonExecutionDetails' ) . resolves ( undefined )
93+ stub ( Python , 'findPythonBin' ) . resolves ( defaultPython )
94+ const mockInstallPackages = stub ( Python , 'installPackages' )
95+ . onFirstCall ( )
96+ . rejects ( new Error ( 'Network error' ) )
97+ stub ( WorkspaceFolders , 'getFirstWorkspaceFolder' ) . returns ( cwd )
98+
99+ const showProgressSpy = spy ( window , 'withProgress' )
100+ const showErrorSpy = spy ( window , 'showErrorMessage' )
101+ const reportProgressErrorSpy = spy ( Toast , 'reportProgressError' )
102+
103+ await autoUpgradeDvc ( )
104+
105+ expect ( showProgressSpy ) . to . be . called
106+ expect ( showErrorSpy ) . not . to . be . called
107+ expect ( reportProgressErrorSpy ) . to . be . calledOnce
108+ expect ( mockInstallPackages ) . to . be . called
109+ expect ( mockInstallPackages ) . to . be . calledWithExactly (
110+ cwd ,
111+ defaultPython ,
112+ 'dvc'
113+ )
114+ } )
115+ } )
116+
117+ describe ( 'autoInstallDvc' , ( ) => {
29118 it ( 'should return early if no Python interpreter is found' , async ( ) => {
30119 stub ( PythonExtension , 'getPythonExecutionDetails' ) . resolves ( undefined )
31120 stub ( Python , 'findPythonBin' ) . resolves ( undefined )
0 commit comments