Skip to content

Commit

Permalink
CLDR-7646 Use TestCache in VettingViewer
Browse files Browse the repository at this point in the history
- add a constructor to CheckCLDR that takes just a CLDRLocale
- move test exclusion in STFactory
  • Loading branch information
srl295 committed Jan 5, 2024
1 parent 5dc06d8 commit e514043
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -308,9 +308,6 @@ public String getPClass() {
*/
private boolean setTests(List<CheckStatus> testList) {
tests = ImmutableList.copyOf(testList);
// remove coverage level errors from payload
tests.removeIf((status) -> status.getSubtype() == Subtype.coverageLevel);

boolean weHaveTests = false;
int errorCount = 0;
int warningCount = 0;
Expand Down Expand Up @@ -752,6 +749,7 @@ private void setShimTests(String base_xpath_string, TestResultBundle checkCldr)
CandidateItem shimItem = new CandidateItem(null);
List<CheckStatus> iTests = new ArrayList<>();
checkCldr.check(base_xpath_string, iTests, null);
STFactory.removeExcludedChecks(iTests);
if (!iTests.isEmpty()) {
// Got a bite.
if (shimItem.setTests(iTests)) {
Expand Down Expand Up @@ -868,6 +866,7 @@ private void updateInheritedValue(CLDRFile ourSrc, TestResultBundle checkCldr) {
List<CheckStatus> iTests = new ArrayList<>();

checkCldr.check(xpath, iTests, inheritedValue);
STFactory.removeExcludedChecks(iTests);

if (TRACE_TIME) {
System.err.println("@@6:" + (System.currentTimeMillis() - lastTime));
Expand Down Expand Up @@ -1928,6 +1927,7 @@ private void populateFromThisXpath(
List<CheckStatus> examplesResult = new ArrayList<>();
if (checkCldr != null) {
checkCldr.check(xpath, checkCldrResult, isExtraPath ? null : ourValue);
STFactory.removeExcludedChecks(checkCldrResult);
checkCldr.getExamples(xpath, isExtraPath ? null : ourValue, examplesResult);
}
if (ourValue != null && ourValue.length() > 0) {
Expand Down Expand Up @@ -1959,6 +1959,7 @@ private void populateFromThisXpathAddItemsForVotes(
if (avalue != null && checkCldr != null) {
List<CheckStatus> item2Result = new ArrayList<>();
checkCldr.check(xpath, item2Result, avalue);
STFactory.removeExcludedChecks(item2Result);
if (!item2Result.isEmpty()) {
item2.setTests(item2Result);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
import java.util.logging.Logger;
import java.util.stream.Collectors;
import org.unicode.cldr.test.CheckCLDR;
import org.unicode.cldr.test.CheckCLDR.CheckStatus;
import org.unicode.cldr.test.CheckCLDR.CheckStatus.Subtype;
import org.unicode.cldr.test.TestCache;
import org.unicode.cldr.util.CLDRConfig;
import org.unicode.cldr.util.CLDRFile;
Expand Down Expand Up @@ -2032,4 +2034,10 @@ public boolean isVisibleInSurveyTool(CLDRLocale l, String dPath) {

return true; // OK.
}

/** remove tests excluded by SurveyTool */
public static List<CheckStatus> removeExcludedChecks(List<CheckStatus> tests) {
tests.removeIf((status) -> status.getSubtype() == Subtype.coverageLevel);
return tests;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,15 @@ public Options(Options options2) {
this.locale = options2.locale;
}

public Options(CLDRLocale locale) {
this.locale = locale;
options = new String[Option.values().length];
set(Option.locale, locale.getBaseName());
StringBuilder sb = new StringBuilder();
sb.append(locale.getBaseName()).append('/');
key = sb.toString().intern();
}

public Options(
CLDRLocale locale,
CheckCLDR.Phase testPhase,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import org.unicode.cldr.test.CheckCLDR;
import org.unicode.cldr.test.CheckCLDR.CheckStatus;
import org.unicode.cldr.test.CheckCLDR.CheckStatus.Subtype;
import org.unicode.cldr.test.CheckCLDR.Options;
import org.unicode.cldr.test.CheckCoverage;
import org.unicode.cldr.test.CheckNew;
import org.unicode.cldr.test.CoverageLevel2;
Expand Down Expand Up @@ -158,7 +157,7 @@ Status getErrorStatus(
private static class DefaultErrorStatus implements ErrorChecker {

private CheckCLDR checkCldr;
private HashMap<String, String> options = new HashMap<>();
private CheckCLDR.Options options = null;
private ArrayList<CheckStatus> result = new ArrayList<>();
private CLDRFile cldrFile;
private final Factory factory;
Expand All @@ -170,18 +169,16 @@ private DefaultErrorStatus(Factory cldrFactory) {
@Override
public Status initErrorStatus(CLDRFile cldrFile) {
this.cldrFile = cldrFile;
options = new HashMap<>();
options = new CheckCLDR.Options(CLDRLocale.getInstance(cldrFile.getLocaleID()));
result = new ArrayList<>();
checkCldr = CheckCLDR.getCheckAll(factory, ".*");
checkCldr.setCldrFileToCheck(cldrFile, new Options(options), result);
// test initialization is handled by TestCache
return Status.ok;
}

@Override
public List<CheckStatus> getErrorCheckStatus(String path, String value) {
String fullPath = cldrFile.getFullXPath(path);
ArrayList<CheckStatus> result2 = new ArrayList<>();
checkCldr.check(path, fullPath, value, new CheckCLDR.Options(options), result2);
factory.getTestCache().getBundle(options).check(path, result2, value);
return result2;
}

Expand All @@ -198,8 +195,7 @@ public Status getErrorStatus(
EnumSet<Subtype> outputSubtypes) {
Status result0 = Status.ok;
StringBuilder errorMessage = new StringBuilder();
String fullPath = cldrFile.getFullXPath(path);
checkCldr.check(path, fullPath, value, new CheckCLDR.Options(options), result);
factory.getTestCache().getBundle(options).check(path, result, value);
for (CheckStatus checkStatus : result) {
final CheckCLDR cause = checkStatus.getCause();
/*
Expand Down

0 comments on commit e514043

Please sign in to comment.