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
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import fiftyone.pipeline.core.data.FlowData;
import fiftyone.pipeline.engines.data.AspectPropertyValue;
import fiftyone.pipeline.engines.exceptions.NoValueException;
import fiftyone.pipeline.engines.fiftyone.data.ComponentMetaData;
import fiftyone.pipeline.engines.fiftyone.data.FiftyOneAspectPropertyMetaData;

import java.util.Arrays;
Expand Down Expand Up @@ -81,13 +82,28 @@ public void validateData(FlowData data, boolean validEvidence) throws NoValueExc
if (validEvidence == false) {
assertEquals("0-0-0-0", elementData.getDeviceId().getValue());
}
int validKeys = 0;
for (String key : data.getEvidence().asKeyMap().keySet()) {
if (engine.getEvidenceKeyFilter().include(key)) {
validKeys++;
}
// Since the detection result shape was unified in device-detection-cxx
// (issue #362), the number of results - and therefore the number of
// matched User-Agents - is determined by the components the engine can
// populate, not by how many evidence keys were supplied. Supplying
// redundant evidence no longer changes it. The exact number depends on
// which components the data file makes available, so assert the bound
// rather than a fixed value, and that valid evidence produces at least
// one result.
int componentCount = 0;
for (ComponentMetaData component : engine.getComponents()) {
componentCount++;
}
int matchedUserAgents = elementData.getUserAgents().getValue().size();
assertTrue(
"There should be no more matched User-Agents (" + matchedUserAgents +
") than components populated by the engine (" + componentCount + ")",
matchedUserAgents <= componentCount);
if (validEvidence) {
assertTrue(
"Valid evidence should produce at least one result",
matchedUserAgents >= 1);
}
assertEquals("validKeys vs userAgents size mismatch", validKeys, elementData.getUserAgents().getValue().size());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import fiftyone.pipeline.core.data.FlowData;
import fiftyone.pipeline.engines.data.AspectPropertyValue;
import fiftyone.pipeline.engines.exceptions.PropertyMissingException;
import fiftyone.pipeline.engines.fiftyone.data.ComponentMetaData;
import fiftyone.pipeline.engines.fiftyone.data.FiftyOneAspectPropertyMetaData;

import java.lang.reflect.Method;
Expand Down Expand Up @@ -59,7 +60,21 @@ public static void matchedUserAgents(Wrapper wrapper) throws Exception {
.process();
ElementData elementData = data.get(wrapper.getEngine().getElementDataKey());
DeviceData device = (DeviceData) elementData;
assertEquals(1, device.getUserAgents().getValue().size());
// Since the detection result shape was unified in
// device-detection-cxx (issue #362), a single User-Agent produces
// one result - and so one matched User-Agent - per component the
// engine populates, rather than exactly one overall. The number
// depends on the data file, so assert the bound here and validate
// every matched substring below.
int componentCount = 0;
for (ComponentMetaData component : wrapper.getComponents()) {
componentCount++;
}
int matchedCount = device.getUserAgents().getValue().size();
assertTrue(
"Expected between 1 and " + componentCount +
" matched User-Agents, got " + matchedCount,
matchedCount >= 1 && matchedCount <= componentCount);
for (String matchedUa : device.getUserAgents().getValue()) {
for (String substring : matchedUa.split("_|\\{|\\}")) {
if (substring.isEmpty() == false) {
Expand Down
Loading