[MediaWiki-commits] [Gerrit] apps...wikipedia[master]: Move TranslationTests to plain JUnit, pt. 1
jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/363759 ) Change subject: Move TranslationTests to plain JUnit, pt. 1 .. Move TranslationTests to plain JUnit, pt. 1 Stops depending on an Android system context for Resource handling and instead iterates over the various strings.xml files, leveraging jsoup to parse the strings directly from the XML and test them. To follow: restore plurals testing. (I'm sure jsoup can handle this similarly, just trying to break things up a bit for ease of reviewing.) Bug: T139546 Bug: T169917 Change-Id: Ie743651ac5a87f5956471759ec614c7a834a0fef --- D app/src/androidTest/java/org/wikipedia/test/TranslationTests.java M app/src/main/res/values-ckb/strings.xml A app/src/test/java/org/wikipedia/language/TranslationTests.java 3 files changed, 339 insertions(+), 417 deletions(-) Approvals: Dbrant: Looks good to me, approved jenkins-bot: Verified diff --git a/app/src/androidTest/java/org/wikipedia/test/TranslationTests.java b/app/src/androidTest/java/org/wikipedia/test/TranslationTests.java deleted file mode 100644 index 9e479e5..000 --- a/app/src/androidTest/java/org/wikipedia/test/TranslationTests.java +++ /dev/null @@ -1,416 +0,0 @@ -package org.wikipedia.test; - -import android.content.res.AssetManager; -import android.content.res.Configuration; -import android.content.res.Resources; -import android.support.annotation.NonNull; -import android.support.annotation.PluralsRes; -import android.support.annotation.StringRes; -import android.util.DisplayMetrics; - -import org.apache.commons.lang3.StringUtils; -import org.junit.Test; -import org.wikipedia.R; -import org.wikipedia.model.BaseModel; -import org.wikipedia.util.ConfigurationCompat; -import org.wikipedia.util.log.L; - -import java.lang.reflect.Field; -import java.text.NumberFormat; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.Locale; - -import static android.support.test.InstrumentationRegistry.getTargetContext; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.is; -import static org.junit.Assert.fail; - -/** - * Tests to make sure that the string resources don't cause any issues. Mainly the goal is to test - * all translations, but even the default strings are tested. - * - * TODO: check content_license_html is valid HTML - */ -public class TranslationTests { -// todo: consider regular expressions. -private static final String POSSIBLE_PARAM_FLOAT_FIRST = "%1$.2f"; -private static final String POSSIBLE_PARAM_FLOAT_THIRD = "%3$.2f"; - -/** Add more if needed, but then also add some tests. */ -private static final String[] POSSIBLE_PARAMS = new String[] {"%s", "%1$s", "%2$s", "%d", -"%1$d", "%2$d", "%.2f", POSSIBLE_PARAM_FLOAT_FIRST, POSSIBLE_PARAM_FLOAT_THIRD, "^1"}; - -private final StringBuilder mismatches = new StringBuilder(); - -@Test public void testAllTranslations() { -setLocale(Locale.ROOT.toString()); -String defaultLang = Locale.getDefault().getLanguage(); -List tagRes = new ResourceCollector("<", "").collectParameterResources(defaultLang); -List noTagRes = new ResourceCollector("<", "").not().collectParameterResources(defaultLang); -List stringParamRes = new ResourceCollector("%s").collectParameterResources(defaultLang); -List twoStringParamRes = new ResourceCollector("%2$s").collectParameterResources(defaultLang); -List twoDecimalParamRes = new ResourceCollector("%2$d").collectParameterResources(defaultLang); -List decimalParamRes = new ResourceCollector("%d").collectParameterResources(defaultLang); -List floatParamRes = new ResourceCollector("%.2f").collectParameterResources(defaultLang); -List floatFirstParamRes = new ResourceCollector(POSSIBLE_PARAM_FLOAT_FIRST).collectParameterResources(defaultLang); -List floatThirdParamRes = new ResourceCollector(POSSIBLE_PARAM_FLOAT_THIRD).collectParameterResources(defaultLang); -List textUtilTemplateParamRes = new ResourceCollector("^1").collectParameterResources(defaultLang); -List pluralRes = collectPluralResources(); -// todo: flag usage of templates {{}}. - -AssetManager assetManager = getResources().getAssets(); -for (String lang : assetManager.getLocales()) { -L.i("locale=" + (lang.equals("") ? "DEFAULT" : lang)); -setLocale(lang); -checkAllStrings(lang); - -// commented out during the transition from 1 param to 0 -// checkTranslationHasNoParameter(R.string.saved_pages_search_empty_message); -// checkTranslationHasNoParameter(R.string.history_search_empty_message); - -if (!lang.startsWith("qq")) { -// tag (html) parameters -for (Res res : tagRes) { -
[MediaWiki-commits] [Gerrit] apps...wikipedia[master]: Move TranslationTests to plain JUnit, pt. 1
Mholloway has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/363759 ) Change subject: Move TranslationTests to plain JUnit, pt. 1 .. Move TranslationTests to plain JUnit, pt. 1 Stops depending on an Android system context for Resource handling and instead iterates over the various strings.xml files, leveraging jsoup to parse the strings directly from the XML and test them. To follow: restore plurals testing. (I'm sure jsoup can handle this similarly, just trying to break things up a bit for ease of reviewing.) Bug: T139546 Change-Id: Ie743651ac5a87f5956471759ec614c7a834a0fef --- D app/src/androidTest/java/org/wikipedia/test/TranslationTests.java M app/src/main/res/values-ckb/strings.xml A app/src/test/java/org/wikipedia/language/TranslationTests.java M app/src/test/java/org/wikipedia/test/TestFileUtil.java 4 files changed, 351 insertions(+), 417 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/apps/android/wikipedia refs/changes/59/363759/1 diff --git a/app/src/androidTest/java/org/wikipedia/test/TranslationTests.java b/app/src/androidTest/java/org/wikipedia/test/TranslationTests.java deleted file mode 100644 index 9e479e5..000 --- a/app/src/androidTest/java/org/wikipedia/test/TranslationTests.java +++ /dev/null @@ -1,416 +0,0 @@ -package org.wikipedia.test; - -import android.content.res.AssetManager; -import android.content.res.Configuration; -import android.content.res.Resources; -import android.support.annotation.NonNull; -import android.support.annotation.PluralsRes; -import android.support.annotation.StringRes; -import android.util.DisplayMetrics; - -import org.apache.commons.lang3.StringUtils; -import org.junit.Test; -import org.wikipedia.R; -import org.wikipedia.model.BaseModel; -import org.wikipedia.util.ConfigurationCompat; -import org.wikipedia.util.log.L; - -import java.lang.reflect.Field; -import java.text.NumberFormat; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.Locale; - -import static android.support.test.InstrumentationRegistry.getTargetContext; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.is; -import static org.junit.Assert.fail; - -/** - * Tests to make sure that the string resources don't cause any issues. Mainly the goal is to test - * all translations, but even the default strings are tested. - * - * TODO: check content_license_html is valid HTML - */ -public class TranslationTests { -// todo: consider regular expressions. -private static final String POSSIBLE_PARAM_FLOAT_FIRST = "%1$.2f"; -private static final String POSSIBLE_PARAM_FLOAT_THIRD = "%3$.2f"; - -/** Add more if needed, but then also add some tests. */ -private static final String[] POSSIBLE_PARAMS = new String[] {"%s", "%1$s", "%2$s", "%d", -"%1$d", "%2$d", "%.2f", POSSIBLE_PARAM_FLOAT_FIRST, POSSIBLE_PARAM_FLOAT_THIRD, "^1"}; - -private final StringBuilder mismatches = new StringBuilder(); - -@Test public void testAllTranslations() { -setLocale(Locale.ROOT.toString()); -String defaultLang = Locale.getDefault().getLanguage(); -List tagRes = new ResourceCollector("<", "").collectParameterResources(defaultLang); -List noTagRes = new ResourceCollector("<", "").not().collectParameterResources(defaultLang); -List stringParamRes = new ResourceCollector("%s").collectParameterResources(defaultLang); -List twoStringParamRes = new ResourceCollector("%2$s").collectParameterResources(defaultLang); -List twoDecimalParamRes = new ResourceCollector("%2$d").collectParameterResources(defaultLang); -List decimalParamRes = new ResourceCollector("%d").collectParameterResources(defaultLang); -List floatParamRes = new ResourceCollector("%.2f").collectParameterResources(defaultLang); -List floatFirstParamRes = new ResourceCollector(POSSIBLE_PARAM_FLOAT_FIRST).collectParameterResources(defaultLang); -List floatThirdParamRes = new ResourceCollector(POSSIBLE_PARAM_FLOAT_THIRD).collectParameterResources(defaultLang); -List textUtilTemplateParamRes = new ResourceCollector("^1").collectParameterResources(defaultLang); -List pluralRes = collectPluralResources(); -// todo: flag usage of templates {{}}. - -AssetManager assetManager = getResources().getAssets(); -for (String lang : assetManager.getLocales()) { -L.i("locale=" + (lang.equals("") ? "DEFAULT" : lang)); -setLocale(lang); -checkAllStrings(lang); - -// commented out during the transition from 1 param to 0 -// checkTranslationHasNoParameter(R.string.saved_pages_search_empty_message); -// checkTranslationHasNoParameter(R.string.history_search_empty_message); - -if (!lang.startsWith("qq")) { -// tag (html)