Skip to content

Commit

Permalink
add integration test for using the exp show data
Browse files Browse the repository at this point in the history
  • Loading branch information
mattseddon committed May 30, 2022
1 parent 7843b88 commit 1cf6754
Show file tree
Hide file tree
Showing 2 changed files with 101 additions and 3 deletions.
2 changes: 1 addition & 1 deletion extension/src/fileSystem/tree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ export class TrackedExplorerTree
const tracked = await collectTrackedPaths(pathItem, (path: string) =>
this.getRepoChildren(dvcRoot, path)
)
const args = [dvcRoot, ...tracked]
const args = [dvcRoot, ...tracked.sort()]

return tryThenMaybeForce(this.internalCommands, commandId, ...args)
}
Expand Down
102 changes: 100 additions & 2 deletions extension/src/test/suite/fileSystem/tree.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { expect } from 'chai'
import { stub, restore, spy } from 'sinon'
import { ensureFileSync } from 'fs-extra'
import {
EventEmitter,
window,
commands,
Uri,
Expand All @@ -27,13 +28,17 @@ import {
} from '../../../commands/external'
import { WEBVIEW_TEST_TIMEOUT } from '../timeouts'
import { Title } from '../../../vscode/title'
import { buildExperiments } from '../experiments/util'
import { Repository } from '../../../repository'
import expShowFixture from '../../fixtures/expShow/output'
import { WorkspaceRepositories } from '../../../repository/workspace'

suite('Tracked Explorer Tree Test Suite', () => {
const { join } = path

const getPathItem = (relPath: string) => ({
const getPathItem = (relPath: string, isTracked = true) => ({
dvcRoot: dvcDemoPath,
isTracked: true,
isTracked,
resourceUri: Uri.file(join(dvcDemoPath, relPath))
})

Expand Down Expand Up @@ -276,6 +281,99 @@ suite('Tracked Explorer Tree Test Suite', () => {
})
})

it('should pull the correct target(s) when asked to dvc.pullTarget a non-tracked directory', async () => {
const { cliReader, experiments, internalCommands, updatesPaused } =
buildExperiments(disposable)

await experiments.isReady()

stub(cliReader, 'listDvcOnlyRecursive').resolves([
{
isdir: false,
isexec: false,
isout: true,
path: 'data/data.xml'
},
{
isdir: false,
isexec: false,
isout: true,
path: 'data/features/test.pkl'
},
{
isdir: false,
isexec: false,
isout: true,
path: 'data/features/train.pkl'
},
{
isdir: false,
isexec: false,
isout: true,
path: 'data/prepared/test.tsv'
},
{
isdir: false,
isexec: false,
isout: true,
path: 'data/prepared/train.tsv'
},
{
isdir: false,
isexec: false,
isout: true,
path: 'evaluation/importance.png'
},
{
isdir: false,
isexec: false,
isout: true,
path: 'model.pkl'
}
])
stub(cliReader, 'status').resolves({})
stub(cliReader, 'diff').resolves({})

const repository = disposable.track(
new Repository(
dvcDemoPath,
internalCommands,
updatesPaused,
new EventEmitter<void>()
)
)

const experimentDataUpdatedEvent = new Promise(resolve =>
disposable.track(
experiments.onDidChangeExperiments(() => resolve(undefined))
)
)

repository.setExperiments(experiments)
experiments.setState(expShowFixture)

stub(WorkspaceRepositories.prototype, 'getRepository').returns(repository)
stub(WorkspaceRepositories.prototype, 'isReady').resolves(undefined)
const mockPull = stub(CliExecutor.prototype, 'pull').resolves(
'target pulled'
)

await Promise.all([repository.isReady(), experimentDataUpdatedEvent])

await commands.executeCommand(
RegisteredCliCommands.PULL_TARGET,
getPathItem('data', false)
)

expect(mockPull).to.be.calledOnce
expect(mockPull).to.be.calledWithExactly(
dvcDemoPath,
join('data', 'data.xml'),
join('data', 'features'),
join('data', 'prepared')
)
})

it('should be able to run dvc.pullTarget without error', async () => {
const relPath = 'data'
stub(path, 'relative').returns(relPath)
Expand Down

0 comments on commit 1cf6754

Please sign in to comment.