in python/src/com/google/idea/blaze/python/run/producers/PyTestContextProvider.java [125:171]
private static String getTestFilterForNamedParameters(
String testBase, PyDecorator decorator, boolean useUnderscores) {
PyExpression[] arguments = getParameterizedDecoratorArgumentList(decorator);
if (arguments == null) {
return null;
}
ArrayList<String> parameterizedFilters = new ArrayList<>();
for (PyExpression argument : arguments) {
if (argument instanceof PyDictLiteralExpression) {
// can be defined as a dict, use the name from element 'testcase_name'
PyDictLiteralExpression dictArgument = (PyDictLiteralExpression) argument;
for (PyKeyValueExpression keyValueExpression : dictArgument.getElements()) {
PyExpression key = keyValueExpression.getKey();
PyExpression value = keyValueExpression.getValue();
if (key instanceof PyStringLiteralExpression
&& value instanceof PyStringLiteralExpression) {
PyStringLiteralExpression keyString = (PyStringLiteralExpression) key;
PyStringLiteralExpression valueString = (PyStringLiteralExpression) value;
if (keyString.getStringValue().equals("testcase_name")) {
String testCaseName = valueString.getStringValue();
String separator = useUnderscores && !testCaseName.startsWith("_") ? "_" : "";
parameterizedFilters.add(testBase + separator + testCaseName);
}
}
}
} else if (argument instanceof PyParenthesizedExpression) {
// can be defined as a tuple, use the name from the 0th element
PyExpression contained = ((PyParenthesizedExpression) argument).getContainedExpression();
if (contained instanceof PyTupleExpression) {
PyTupleExpression tupleArgument = (PyTupleExpression) contained;
PyExpression[] tupleElements = tupleArgument.getElements();
if (tupleElements.length > 0 && tupleElements[0] instanceof PyStringLiteralExpression) {
PyStringLiteralExpression testCaseLiteral =
(PyStringLiteralExpression) tupleElements[0];
String testCaseName = testCaseLiteral.getStringValue();
String separator = useUnderscores && !testCaseName.startsWith("_") ? "_" : "";
parameterizedFilters.add(testBase + separator + testCaseName);
}
}
}
}
if (parameterizedFilters.isEmpty()) {
return testBase;
}
return Joiner.on(" ").join(parameterizedFilters);
}