Skip to content

Commit

Permalink
update all remaining test fixtures
Browse files Browse the repository at this point in the history
  • Loading branch information
mattseddon committed Apr 13, 2023
1 parent 351e42a commit 2bbe80f
Show file tree
Hide file tree
Showing 38 changed files with 2,433 additions and 5,421 deletions.
2 changes: 1 addition & 1 deletion demo
Submodule demo updated 1 files
+2 −2 requirements.txt
2 changes: 1 addition & 1 deletion extension/src/cli/dvc/reader.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ describe('CliReader', () => {
getMockedProcess(JSON.stringify(expShowFixture))
)

const cliOutput = await dvcReader.expShow(cwd)
const cliOutput = await dvcReader.expShow_(cwd)
expect(cliOutput).toStrictEqual(expShowFixture)
expect(mockedCreateProcess).toHaveBeenCalledWith({
args: ['exp', 'show', JSON_FLAG],
Expand Down
22 changes: 17 additions & 5 deletions extension/src/experiments/columns/collect/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,22 @@ import {
collectChanges,
collectChanges_,
collectColumns,
collectColumns_
collectColumns_,
collectRelativeMetricsFiles
} from '.'
import { timestampColumn } from '../constants'
import { buildMetricOrParamPath } from '../paths'
import { Column, ColumnType } from '../../webview/contract'
import outputFixture from '../../../test/fixtures/expShow/base/output_'
import outputFixture from '../../../test/fixtures/expShow/base/output'
import columnsFixture from '../../../test/fixtures/expShow/base/columns'
import workspaceChangesFixture from '../../../test/fixtures/expShow/base/workspaceChanges'
import uncommittedDepsFixture from '../../../test/fixtures/expShow/uncommittedDeps/output'
import {
ExperimentsOutput,
ExperimentStatus,
EXPERIMENT_WORKSPACE_ID,
ValueTree
ValueTree,
ExpStateData
} from '../../../cli/dvc/contract'
import { getConfigValue } from '../../../vscode/config'

Expand Down Expand Up @@ -454,9 +456,11 @@ describe('collectChanges', () => {
}

it('should mark new dep files as changes', () => {
const changes = collectChanges(uncommittedDepsFixture)
const changes = collectChanges_(uncommittedDepsFixture)
expect(changes).toStrictEqual(
Object.keys(uncommittedDepsFixture.workspace.baseline.data?.deps || {})
Object.keys(
(uncommittedDepsFixture[0] as { data: ExpStateData }).data.deps || {}
)
.map(dep => `deps:${dep}`)
.sort()
)
Expand Down Expand Up @@ -761,3 +765,11 @@ describe('collectChanges', () => {
])
})
})

describe('collectRelativeMetricsFiles', () => {
it('should return the expected metrics files from the test fixture', () => {
expect(collectRelativeMetricsFiles(outputFixture)).toStrictEqual([
'summary.json'
])
})
})
14 changes: 14 additions & 0 deletions extension/src/experiments/columns/collect/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,3 +167,17 @@ export const collectParamsFiles_ = (
.map(file => standardizePath(join(dvcRoot, file)))
return new Set(files)
}

export const collectRelativeMetricsFiles = (
output: ExpShowOutput
): string[] => {
const [workspace] = output
if (hasError(workspace)) {
return []
}
const files = Object.keys(workspace.data.metrics || {})
.filter(Boolean)
.sort()

return [...new Set(files)]
}
20 changes: 10 additions & 10 deletions extension/src/experiments/columns/model.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { buildMockMemento } from '../../test/util'
import { Status } from '../../path/selection/model'
import { PersistenceKey } from '../../persistence/constants'
import { ColumnType } from '../webview/contract'
import outputFixture from '../../test/fixtures/expShow/base/output_'
import outputFixture from '../../test/fixtures/expShow/base/output'
import columnsFixture from '../../test/fixtures/expShow/base/columns'
import {
deeplyNestedColumnsWithHeightOf10,
Expand Down Expand Up @@ -75,7 +75,7 @@ describe('ColumnsModel', () => {
buildMockMemento(),
mockedColumnsOrderOrStatusChanged
)
await model.transformAndSet(survivalOutputFixture)
await model.transformAndSet_(survivalOutputFixture)
expect(model.getSelected()).toStrictEqual(survivalColumnsFixture)
})

Expand All @@ -85,7 +85,7 @@ describe('ColumnsModel', () => {
buildMockMemento(),
mockedColumnsOrderOrStatusChanged
)
await model.transformAndSet(deeplyNestedOutputFixture)
await model.transformAndSet_(deeplyNestedOutputFixture)
expect(mockedGetConfigValue).toHaveBeenCalled()
expect(model.getSelected()).toStrictEqual(deeplyNestedColumnsFixture)
})
Expand All @@ -97,7 +97,7 @@ describe('ColumnsModel', () => {
buildMockMemento(),
mockedColumnsOrderOrStatusChanged
)
await model.transformAndSet(deeplyNestedOutputFixture)
await model.transformAndSet_(deeplyNestedOutputFixture)
expect(mockedGetConfigValue).toHaveBeenCalled()
expect(model.getSelected()).toStrictEqual(deeplyNestedColumnsWithHeightOf10)
})
Expand All @@ -109,7 +109,7 @@ describe('ColumnsModel', () => {
buildMockMemento(),
mockedColumnsOrderOrStatusChanged
)
await model.transformAndSet(deeplyNestedOutputFixture)
await model.transformAndSet_(deeplyNestedOutputFixture)
expect(mockedGetConfigValue).toHaveBeenCalled()
expect(model.getSelected()).toStrictEqual(deeplyNestedColumnsWithHeightOf3)
})
Expand All @@ -121,7 +121,7 @@ describe('ColumnsModel', () => {
buildMockMemento(),
mockedColumnsOrderOrStatusChanged
)
await model.transformAndSet(deeplyNestedOutputFixture)
await model.transformAndSet_(deeplyNestedOutputFixture)
expect(mockedGetConfigValue).toHaveBeenCalled()
expect(model.getSelected()).toStrictEqual(deeplyNestedColumnsWithHeightOf2)
})
Expand All @@ -133,7 +133,7 @@ describe('ColumnsModel', () => {
buildMockMemento(),
mockedColumnsOrderOrStatusChanged
)
await model.transformAndSet(deeplyNestedOutputFixture)
await model.transformAndSet_(deeplyNestedOutputFixture)
expect(mockedGetConfigValue).toHaveBeenCalled()
expect(model.getSelected()).toStrictEqual(deeplyNestedColumnsWithHeightOf1)
})
Expand All @@ -145,7 +145,7 @@ describe('ColumnsModel', () => {
buildMockMemento(),
mockedColumnsOrderOrStatusChanged
)
await model.transformAndSet(deeplyNestedOutputFixture)
await model.transformAndSet_(deeplyNestedOutputFixture)
expect(mockedGetConfigValue).toHaveBeenCalled()
expect(model.getSelected()).toStrictEqual(deeplyNestedColumnsWithHeightOf10)
})
Expand All @@ -157,7 +157,7 @@ describe('ColumnsModel', () => {
buildMockMemento(),
mockedColumnsOrderOrStatusChanged
)
await model.transformAndSet(deeplyNestedOutputFixture)
await model.transformAndSet_(deeplyNestedOutputFixture)
expect(mockedGetConfigValue).toHaveBeenCalled()
expect(model.getSelected()).toStrictEqual(deeplyNestedColumnsWithHeightOf10)
})
Expand All @@ -168,7 +168,7 @@ describe('ColumnsModel', () => {
buildMockMemento(),
mockedColumnsOrderOrStatusChanged
)
await model.transformAndSet(dataTypesOutputFixture)
await model.transformAndSet_(dataTypesOutputFixture)
expect(model.getSelected()).toStrictEqual(dataTypesColumnsFixture)
})

Expand Down
12 changes: 10 additions & 2 deletions extension/src/experiments/columns/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
collectChanges_,
collectColumns,
collectColumns_,
collectRelativeMetricsFiles,
collectParamsFiles,
collectParamsFiles_
} from './collect'
Expand All @@ -17,6 +18,7 @@ export class ColumnsModel extends PathSelectionModel<Column> {
private columnWidthsState: Record<string, number> = {}
private columnsChanges: string[] = []
private paramsFiles = new Set<string>()
private relativeMetricsFiles: string[] = []

constructor(
dvcRoot: string,
Expand Down Expand Up @@ -58,6 +60,10 @@ export class ColumnsModel extends PathSelectionModel<Column> {
return this.paramsFiles
}

public getRelativeMetricsFiles() {
return this.relativeMetricsFiles
}

public transformAndSet(data: ExperimentsOutput) {
return Promise.all([this.transformAndSetColumns(data)])
}
Expand Down Expand Up @@ -181,9 +187,10 @@ export class ColumnsModel extends PathSelectionModel<Column> {
}

private async transformAndSetColumns_(data: ExpShowOutput) {
const [columns, paramsFiles] = await Promise.all([
const [columns, paramsFiles, relativeMetricsFiles] = await Promise.all([
collectColumns_(data),
collectParamsFiles_(this.dvcRoot, data)
collectParamsFiles_(this.dvcRoot, data),
collectRelativeMetricsFiles(data)
])

this.setNewStatuses(columns)
Expand All @@ -195,6 +202,7 @@ export class ColumnsModel extends PathSelectionModel<Column> {
}

this.paramsFiles = paramsFiles
this.relativeMetricsFiles = relativeMetricsFiles
}

private transformAndSetChanges_(data: ExpShowOutput) {
Expand Down
2 changes: 1 addition & 1 deletion extension/src/experiments/data/collect.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { join } from 'path'
import { collectFiles } from './collect'
import { EXPERIMENT_WORKSPACE_ID } from '../../cli/dvc/contract'
import expShowFixture from '../../test/fixtures/expShow/base/output_'
import expShowFixture from '../../test/fixtures/expShow/base/output'

describe('collectFiles', () => {
it('should collect all of the available files from the test fixture', () => {
Expand Down
4 changes: 4 additions & 0 deletions extension/src/experiments/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,10 @@ export class Experiments extends BaseRepository<TableData> {
return this.columns.hasNonDefaultColumns()
}

public getRelativeMetricsFiles() {
return this.columns.getRelativeMetricsFiles()
}

protected sendInitialWebviewData() {
return this.webviewMessages.sendWebviewMessage()
}
Expand Down
28 changes: 10 additions & 18 deletions extension/src/experiments/model/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ import { join } from 'path'
import { commands } from 'vscode'
import { ExperimentsModel } from '.'
import outputFixture from '../../test/fixtures/expShow/base/output'
import outputFixture_ from '../../test/fixtures/expShow/base/output_'
import rowsFixture from '../../test/fixtures/expShow/base/rows'
import rowsFixture_ from '../../test/fixtures/expShow/base/rows_'
import deeplyNestedRowsFixture from '../../test/fixtures/expShow/deeplyNested/rows'
import deeplyNestedOutputFixture from '../../test/fixtures/expShow/deeplyNested/output'
import uncommittedDepsFixture from '../../test/fixtures/expShow/uncommittedDeps/output'
Expand Down Expand Up @@ -57,21 +55,15 @@ describe('ExperimentsModel', () => {
return { data }
}

it('should return the expected rows when given the output fixture', () => {
const model = new ExperimentsModel('', buildMockMemento())
model.transformAndSet(outputFixture, false, '')
expect(model.getRowData()).toStrictEqual(rowsFixture)
})

it('should return the expected rows when given the output fixture_', () => {
const model = new ExperimentsModel('', buildMockMemento())
model.transformAndSet_(outputFixture_, false, '')
expect(model.getRowData()).toStrictEqual(rowsFixture_)
model.transformAndSet_(outputFixture, false, '')
expect(model.getRowData()).toStrictEqual(rowsFixture)
})

it('should return the expected rows when given the survival fixture', () => {
const model = new ExperimentsModel('', buildMockMemento())
model.transformAndSet(survivalOutputFixture, false, '')
model.transformAndSet_(survivalOutputFixture, false, '')
expect(model.getRowData()).toStrictEqual(survivalRowsFixture)
})

Expand Down Expand Up @@ -218,20 +210,20 @@ describe('ExperimentsModel', () => {

it('should handle deps have all null properties (never been committed)', () => {
const model = new ExperimentsModel('', buildMockMemento())
model.transformAndSet(uncommittedDepsFixture, false, '')
model.transformAndSet_(uncommittedDepsFixture, false, '')
const [workspace] = model.getWorkspaceAndCommits()
expect(workspace.deps).toStrictEqual({})
})

it('should return the expected rows when given the deeply nested output fixture', () => {
const model = new ExperimentsModel('', buildMockMemento())
model.transformAndSet(deeplyNestedOutputFixture, false, '')
model.transformAndSet_(deeplyNestedOutputFixture, false, '')
expect(model.getRowData()).toStrictEqual(deeplyNestedRowsFixture)
})

it('should return the expected rows when given the data types output fixture', () => {
const model = new ExperimentsModel('', buildMockMemento())
model.transformAndSet(dataTypesOutputFixture, false, '')
model.transformAndSet_(dataTypesOutputFixture, false, '')
expect(model.getRowData()).toStrictEqual(dataTypesRowsFixture)
})

Expand Down Expand Up @@ -272,31 +264,31 @@ describe('ExperimentsModel', () => {

it('should fetch commit params', () => {
const model = new ExperimentsModel('', buildMockMemento())
model.transformAndSet(outputFixture, false, '')
model.transformAndSet_(outputFixture, false, '')

const commitParams = model.getExperimentParams('main')
expect(definedAndNonEmpty(commitParams)).toBe(true)
})

it('should fetch workspace params', () => {
const model = new ExperimentsModel('', buildMockMemento())
model.transformAndSet(outputFixture, false, '')
model.transformAndSet_(outputFixture, false, '')

const workspaceParams = model.getExperimentParams(EXPERIMENT_WORKSPACE_ID)
expect(definedAndNonEmpty(workspaceParams)).toBe(true)
})

it("should fetch an experiment's params", () => {
const model = new ExperimentsModel('', buildMockMemento())
model.transformAndSet(outputFixture, false, '')
model.transformAndSet_(outputFixture, false, '')

const experimentParams = model.getExperimentParams('exp-e7a67')
expect(definedAndNonEmpty(experimentParams)).toBe(true)
})

it("should fetch an empty array if the experiment's params cannot be found", () => {
const model = new ExperimentsModel('', buildMockMemento())
model.transformAndSet(outputFixture, false, '')
model.transformAndSet_(outputFixture, false, '')

const noParams = model.getExperimentParams('not-an-experiment')
expect(definedAndNonEmpty(noParams)).toBe(false)
Expand Down
12 changes: 4 additions & 8 deletions extension/src/experiments/model/modify/collect.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ describe('collectFlatExperimentParams', () => {
const params = collectFlatExperimentParams(rowsFixture[0].params)
expect(params).toStrictEqual([
{ path: appendColumnToPath('params.yaml', 'code_names'), value: [0, 1] },
{ path: appendColumnToPath('params.yaml', 'epochs'), value: 2 },
{ path: appendColumnToPath('params.yaml', 'epochs'), value: 5 },
{
path: appendColumnToPath('params.yaml', 'learning_rate'),
value: 2.2e-7
value: 2.1e-7
},
{
path: appendColumnToPath('params.yaml', 'dvc_logs_dir'),
Expand All @@ -23,15 +23,11 @@ describe('collectFlatExperimentParams', () => {
},
{
path: appendColumnToPath('params.yaml', 'dropout'),
value: 0.122
value: 0.124
},
{
path: appendColumnToPath('params.yaml', 'process', 'threshold'),
value: 0.86
},
{
path: appendColumnToPath('params.yaml', 'process', 'test_arg'),
value: 'string'
value: 0.85
},
{
path: appendColumnToPath(join('nested', 'params.yaml'), 'test'),
Expand Down
Loading

0 comments on commit 2bbe80f

Please sign in to comment.