Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions extension/src/test/suite/cli/runner.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { CliResult, CliStarted } from '../../../cli'
import * as Telemetry from '../../../telemetry'
import { EventName } from '../../../telemetry/constants'
import { WEBVIEW_TEST_TIMEOUT } from '../timeouts'
import { spyOnPrivateMemberMethod } from '../util'

suite('CLI Runner Test Suite', () => {
const disposable = Disposable.fn()
Expand Down Expand Up @@ -49,8 +50,11 @@ suite('CLI Runner Test Suite', () => {

expect(dvcRunner.isExperimentRunning()).to.be.true

// eslint-disable-next-line @typescript-eslint/no-explicit-any
const closeSpy = spy((dvcRunner as any).pseudoTerminal, 'close')
const closeSpy = spyOnPrivateMemberMethod(
dvcRunner,
'pseudoTerminal',
'close'
)

await dvcRunner.stop()
expect(closeSpy).to.be.calledOnce
Expand Down
9 changes: 5 additions & 4 deletions extension/src/test/suite/experiments/data/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import expShowFixture from '../../../fixtures/expShow/output'
import {
bypassProcessManagerDebounce,
getFirstArgOfCall,
getMockNow
getMockNow,
stubPrivateMemberMethod
} from '../../util'
import { dvcDemoPath } from '../../../util'
import {
Expand Down Expand Up @@ -191,9 +192,9 @@ suite('Experiments Data Test Suite', () => {

await data.isReady()
bypassProcessManagerDebounce(mockNow)
const mockIsOngoingOrQueued = stub(
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(data as any).processManager,
const mockIsOngoingOrQueued = stubPrivateMemberMethod(
data,
'processManager',
'isOngoingOrQueued'
).returns(false)

Expand Down
47 changes: 11 additions & 36 deletions extension/src/test/suite/experiments/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
QuickPickItem,
ViewColumn
} from 'vscode'
import { buildExperiments } from './util'
import { buildExperiments, stubWorkspaceExperimentsGetters } from './util'
import { Disposable } from '../../../extension'
import expShowFixture from '../../fixtures/expShow/output'
import rowsFixture from '../../fixtures/expShow/rows'
Expand Down Expand Up @@ -61,7 +61,6 @@ import { EventName } from '../../../telemetry/constants'
import * as VscodeContext from '../../../vscode/context'
import { Title } from '../../../vscode/title'
import { ExperimentFlag } from '../../../cli/dvc/constants'
import { WorkspaceExperiments } from '../../../experiments/workspace'
import { DvcExecutor } from '../../../cli/dvc/executor'
import { shortenForLabel } from '../../../util/string'
import { GitExecutor } from '../../../cli/git/executor'
Expand Down Expand Up @@ -426,7 +425,8 @@ suite('Experiments Test Suite', () => {
DvcExecutor.prototype,
'experimentApply'
).resolves(undefined)
stub(WorkspaceExperiments.prototype, 'getRepository').returns(experiments)

stubWorkspaceExperimentsGetters(dvcDemoPath, experiments)

mockMessageReceived.fire({
payload: mockExperimentId,
Expand All @@ -452,12 +452,7 @@ suite('Experiments Test Suite', () => {
'experimentBranch'
).resolves('undefined')

stub(
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(WorkspaceExperiments as any).prototype,
'getOnlyOrPickProject'
).returns(dvcDemoPath)
stub(WorkspaceExperiments.prototype, 'getRepository').returns(experiments)
stubWorkspaceExperimentsGetters(dvcDemoPath, experiments)

const webview = await experiments.showWebview()
const mockMessageReceived = getMessageReceivedEmitter(webview)
Expand Down Expand Up @@ -511,7 +506,7 @@ suite('Experiments Test Suite', () => {
})
)

stub(WorkspaceExperiments.prototype, 'getRepository').returns(experiments)
stubWorkspaceExperimentsGetters(dvcDemoPath, experiments)

const webview = await experiments.showWebview()
const mockMessageReceived = getMessageReceivedEmitter(webview)
Expand Down Expand Up @@ -546,12 +541,8 @@ suite('Experiments Test Suite', () => {
'params.yaml:weight_decay=0'
]

stub(
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(WorkspaceExperiments as any).prototype,
'getOnlyOrPickProject'
).returns(dvcDemoPath)
stub(WorkspaceExperiments.prototype, 'getRepository').returns(experiments)
stubWorkspaceExperimentsGetters(dvcDemoPath, experiments)

stub(experiments, 'pickAndModifyParams').resolves(mockModifiedParams)
const mockQueueExperiment = stub(
dvcExecutor,
Expand Down Expand Up @@ -586,12 +577,8 @@ suite('Experiments Test Suite', () => {
'params.yaml:weight_decay=0'
]

stub(
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(WorkspaceExperiments as any).prototype,
'getOnlyOrPickProject'
).returns(dvcDemoPath)
stub(WorkspaceExperiments.prototype, 'getRepository').returns(experiments)
stubWorkspaceExperimentsGetters(dvcDemoPath, experiments)

stub(experiments, 'pickAndModifyParams').resolves(mockModifiedParams)
const mockRunExperiment = stub(dvcRunner, 'runExperiment').resolves(
undefined
Expand Down Expand Up @@ -629,13 +616,7 @@ suite('Experiments Test Suite', () => {

stub(experiments, 'pickAndModifyParams').resolves(mockModifiedParams)

stub(
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(WorkspaceExperiments as any).prototype,
'getOnlyOrPickProject'
).returns(dvcDemoPath)

stub(WorkspaceExperiments.prototype, 'getRepository').returns(experiments)
stubWorkspaceExperimentsGetters(dvcDemoPath, experiments)

const webview = await experiments.showWebview()
const mockMessageReceived = getMessageReceivedEmitter(webview)
Expand Down Expand Up @@ -701,13 +682,7 @@ suite('Experiments Test Suite', () => {
'queued experiment cannot be selected'
).to.be.false

stub(
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(WorkspaceExperiments as any).prototype,
'getOnlyOrPickProject'
).returns(dvcDemoPath)

stub(WorkspaceExperiments.prototype, 'getRepository').returns(experiments)
stubWorkspaceExperimentsGetters(dvcDemoPath, experiments)

const webview = await experiments.showWebview()
const mockMessageReceived = getMessageReceivedEmitter(webview)
Expand Down
52 changes: 14 additions & 38 deletions extension/src/test/suite/experiments/model/filterBy/tree.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,14 @@ import {
Operator
} from '../../../../../experiments/model/filterBy'
import { buildMockMemento, dvcDemoPath } from '../../../../util'
import { experimentsUpdatedEvent } from '../../../util'
import {
experimentsUpdatedEvent,
stubPrivateMethod,
stubPrivatePrototypeMethod
} from '../../../util'
import { buildMetricOrParamPath } from '../../../../../experiments/columns/paths'
import { RegisteredCommands } from '../../../../../commands/external'
import { buildExperiments } from '../../util'
import { buildExperiments, stubWorkspaceExperimentsGetters } from '../../util'
import {
ColumnType,
Experiment,
Expand Down Expand Up @@ -60,12 +64,7 @@ suite('Experiments Filter By Tree Test Suite', () => {
await experiments.isReady()
await experiments.showWebview()

stub(WorkspaceExperiments.prototype, 'getRepository').returns(experiments)
stub(
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(WorkspaceExperiments as any).prototype,
'getFocusedOrOnlyOrPickProject'
).returns(dvcDemoPath)
stubWorkspaceExperimentsGetters(dvcDemoPath, experiments)

const accuracyPath = buildMetricOrParamPath(
ColumnType.METRICS,
Expand Down Expand Up @@ -169,12 +168,7 @@ suite('Experiments Filter By Tree Test Suite', () => {

await experiments.isReady()

stub(WorkspaceExperiments.prototype, 'getRepository').returns(experiments)
stub(
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(WorkspaceExperiments as any).prototype,
'getFocusedOrOnlyOrPickProject'
).returns(dvcDemoPath)
stubWorkspaceExperimentsGetters(dvcDemoPath, experiments)

const lossPath = buildMetricOrParamPath(
ColumnType.METRICS,
Expand Down Expand Up @@ -237,8 +231,7 @@ suite('Experiments Filter By Tree Test Suite', () => {

mockShowInputBox.resetHistory()

// eslint-disable-next-line @typescript-eslint/no-explicit-any
stub((WorkspaceExperiments as any).prototype, 'getDvcRoots').returns([
stubPrivatePrototypeMethod(WorkspaceExperiments, 'getDvcRoots').returns([
dvcDemoPath
])
stub(WorkspaceExperiments.prototype, 'isReady').resolves(undefined)
Expand Down Expand Up @@ -270,12 +263,7 @@ suite('Experiments Filter By Tree Test Suite', () => {
}
const filterId = getFilterId(filter)

stub(WorkspaceExperiments.prototype, 'getRepository').returns(experiments)
stub(
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(WorkspaceExperiments as any).prototype,
'getFocusedOrOnlyOrPickProject'
).returns(dvcDemoPath)
stubWorkspaceExperimentsGetters(dvcDemoPath, experiments)

await addFilterViaQuickInput(experiments, filter)

Expand Down Expand Up @@ -327,8 +315,7 @@ suite('Experiments Filter By Tree Test Suite', () => {
it('should handle the user exiting from the choose repository quick pick', async () => {
const mockShowQuickPick = stub(window, 'showQuickPick')

// eslint-disable-next-line @typescript-eslint/no-explicit-any
stub((WorkspaceExperiments as any).prototype, 'getDvcRoots').returns([
stub(WorkspaceExperiments.prototype, 'getDvcRoots').returns([
dvcDemoPath,
'mockRoot'
])
Expand Down Expand Up @@ -416,8 +403,7 @@ suite('Experiments Filter By Tree Test Suite', () => {
'3 Experiments, 9 Checkpoints Filtered'
)

// eslint-disable-next-line @typescript-eslint/no-explicit-any
stub(experimentsModel as any, 'getFilteredExperiments')
stubPrivateMethod(experimentsModel, 'getFilteredExperiments')
.onFirstCall()
.returns([
{ id: '0ef13xs', type: ExperimentType.CHECKPOINT } as Experiment & {
Expand Down Expand Up @@ -473,12 +459,7 @@ suite('Experiments Filter By Tree Test Suite', () => {
await experiments.isReady()
await experiments.showWebview()

stub(WorkspaceExperiments.prototype, 'getRepository').returns(experiments)
stub(
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(WorkspaceExperiments as any).prototype,
'getFocusedOrOnlyOrPickProject'
).returns(dvcDemoPath)
stubWorkspaceExperimentsGetters(dvcDemoPath, experiments)

await addFilterViaQuickInput(experiments, starredFilter)

Expand Down Expand Up @@ -514,12 +495,7 @@ suite('Experiments Filter By Tree Test Suite', () => {

await experiments.isReady()

stub(WorkspaceExperiments.prototype, 'getRepository').returns(experiments)
stub(
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(WorkspaceExperiments as any).prototype,
'getFocusedOrOnlyOrPickProject'
).returns(dvcDemoPath)
stubWorkspaceExperimentsGetters(dvcDemoPath, experiments)

const mockAddFilter = stub(experimentsModel, 'addFilter')

Expand Down
24 changes: 5 additions & 19 deletions extension/src/test/suite/experiments/model/sortBy/tree.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
ColumnType
} from '../../../../../experiments/webview/contract'
import { QuickPickItemWithValue } from '../../../../../vscode/quickPick'
import { buildExperiments } from '../../util'
import { buildExperiments, stubWorkspaceExperimentsGetters } from '../../util'
import { experimentsUpdatedEvent } from '../../../util'
import { dvcDemoPath } from '../../../../util'
import { buildMetricOrParamPath } from '../../../../../experiments/columns/paths'
Expand Down Expand Up @@ -158,16 +158,8 @@ suite('Experiments Sort By Tree Test Suite', () => {
get(exp, selector)
)

// eslint-disable-next-line @typescript-eslint/no-explicit-any
stub((WorkspaceExperiments as any).prototype, 'getDvcRoots').returns([
dvcDemoPath
])
stub(WorkspaceExperiments.prototype, 'getRepository').returns(experiments)
stub(
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(WorkspaceExperiments as any).prototype,
'getFocusedOrOnlyOrPickProject'
).returns(dvcDemoPath)
stub(WorkspaceExperiments.prototype, 'getDvcRoots').returns([dvcDemoPath])
stubWorkspaceExperimentsGetters(dvcDemoPath, experiments)

// Setup done, perform the test

Expand Down Expand Up @@ -261,8 +253,7 @@ suite('Experiments Sort By Tree Test Suite', () => {
it('should handle the user exiting from the choose repository quick pick', async () => {
const mockShowQuickPick = stub(window, 'showQuickPick')

// eslint-disable-next-line @typescript-eslint/no-explicit-any
stub((WorkspaceExperiments as any).prototype, 'getDvcRoots').returns([
stub(WorkspaceExperiments.prototype, 'getDvcRoots').returns([
dvcDemoPath,
'mockRoot'
])
Expand Down Expand Up @@ -294,12 +285,7 @@ suite('Experiments Sort By Tree Test Suite', () => {

await experiments.isReady()

stub(WorkspaceExperiments.prototype, 'getRepository').returns(experiments)
stub(
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(WorkspaceExperiments as any).prototype,
'getFocusedOrOnlyOrPickProject'
).returns(dvcDemoPath)
stubWorkspaceExperimentsGetters(dvcDemoPath, experiments)

const mockAddSort = stub(experimentsModel, 'addSort')

Expand Down
Loading