Skip to content

Commit

Permalink
Fix golden file test indexing nonexistent tensor (#7527)
Browse files Browse the repository at this point in the history
Use `.toEqual(jasmine.anything())` instead of `.not.toEqual(null)` to catch both
`null` and `undefined`.

Use `model.outputs.map(output => output.name)` instead of `model.outputNodes` to
get the output node name without the numerical index.
  • Loading branch information
mattsoulanille authored Mar 28, 2023
1 parent 9923395 commit 95a2873
Show file tree
Hide file tree
Showing 2 changed files with 169 additions and 53 deletions.
18 changes: 12 additions & 6 deletions e2e/integration_tests/graph_model_golden_tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,16 @@ describeWithFlags(`${REGRESSION} graph_model_golden`, ALL_ENVS, () => {
...intermediateNodeNames.filter(
(unused, i) =>
(i % INTERMEDIATE_NODE_TESTS_NUM) + 1 === batchId),
...model.outputNodes,
...model.outputs.map(output => output.name),
];

const goldens = targetNodeNames.map((name) => {
return modelGolden.intermediateDetails[name];
const details = modelGolden.intermediateDetails[name];
if (details == null) {
throw new Error(`Golden file is missing tensor details for ` +
`${name}`);
}
return details;
});

tfc.tidy(() => {
Expand Down Expand Up @@ -112,8 +118,8 @@ async function loadModelGolden(goldenFilename: string) {

async function expectTensorToEqualGolden(
tensor: tfc.Tensor, golden: TensorDetail) {
expect(tensor).not.toEqual(null);
expect(golden).not.toEqual(null);
expect(tensor).toEqual(jasmine.anything());
expect(golden).toEqual(jasmine.anything());

expect(isTensorDetail(golden));
expect(tensor.isDisposed).toEqual(false);
Expand All @@ -125,8 +131,8 @@ async function expectTensorToEqualGolden(
async function expectTensorsToEqualGoldens(
tensors: tfc.Tensor|tfc.Tensor[]|tfc.NamedTensorMap,
goldens: TensorDetail|TensorDetail[]|Record<string, TensorDetail>) {
expect(tensors).not.toEqual(null);
expect(goldens).not.toEqual(null);
expect(tensors).toEqual(jasmine.anything());
expect(goldens).toEqual(jasmine.anything());
if (tensors instanceof tfc.Tensor) {
expectTensorToEqualGolden(tensors, goldens as TensorDetail);
} else if (Array.isArray(tensors)) {
Expand Down
Loading

0 comments on commit 95a2873

Please sign in to comment.