use of com.facebook.buck.python.NeededCoverageSpec in project buck by facebook.
the class NeededCoverageSpecTypeCoercer method coerce.
@Override
public NeededCoverageSpec coerce(CellPathResolver cellRoots, ProjectFilesystem filesystem, Path pathRelativeToProjectRoot, Object object) throws CoerceFailedException {
if (object instanceof NeededCoverageSpec) {
return (NeededCoverageSpec) object;
}
if (object instanceof Collection<?>) {
Collection<?> collection = (Collection<?>) object;
if (collection.size() == 2 || collection.size() == 3) {
Iterator<?> iter = collection.iterator();
Float neededRatio = floatTypeCoercer.coerce(cellRoots, filesystem, pathRelativeToProjectRoot, iter.next());
if (neededRatio < 0 || neededRatio > 1) {
throw CoerceFailedException.simple(object, getOutputClass(), "the needed coverage ratio should be in range [0; 1]");
}
BuildTarget buildTarget = buildTargetTypeCoercer.coerce(cellRoots, filesystem, pathRelativeToProjectRoot, iter.next());
Optional<String> pathName = Optional.empty();
if (iter.hasNext()) {
pathName = Optional.of(pathNameTypeCoercer.coerce(cellRoots, filesystem, pathRelativeToProjectRoot, iter.next()));
}
return NeededCoverageSpec.of(neededRatio, buildTarget, pathName);
}
}
throw CoerceFailedException.simple(object, getOutputClass(), "input should be a tuple of needed coverage ratio, a build target, and optionally a path");
}
use of com.facebook.buck.python.NeededCoverageSpec in project buck by facebook.
the class TypeCoercerTest method coerceToNeededCoverageSpec.
@Test
public void coerceToNeededCoverageSpec() throws NoSuchFieldException, CoerceFailedException {
Type type = TestFields.class.getField("listOfNeededCoverageSpecs").getGenericType();
TypeCoercer<?> coercer = typeCoercerFactory.typeCoercerForType(type);
ImmutableList<?> input = ImmutableList.of(ImmutableList.of(0.0, "//some:build-target"), ImmutableList.of(0.9, "//other/build:target"), ImmutableList.of(1.0, "//:target", "some/path.py"));
Object result = coercer.coerce(cellRoots, filesystem, Paths.get(""), input);
ImmutableList<NeededCoverageSpec> expectedResult = ImmutableList.of(NeededCoverageSpec.of(0.0f, BuildTargetFactory.newInstance("//some:build-target"), Optional.empty()), NeededCoverageSpec.of(0.9f, BuildTargetFactory.newInstance("//other/build:target"), Optional.empty()), NeededCoverageSpec.of(1.0f, BuildTargetFactory.newInstance("//:target"), Optional.of("some/path.py")));
assertEquals(expectedResult, result);
}
Aggregations