Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add likely_subtags: data generation, node executor #93

Merged
merged 9 commits into from
Aug 23, 2023
38 changes: 23 additions & 15 deletions executors/node/executor.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

The type of test determines the corresponding test function that then
receives the test case. This includes the type of operation, e.g.,
collation, number format, locale matching, etc.
collation, number format, locale matching, likely subtags, etc.

The data includes parameters needed to specify the function called as well
as the test data passed to the function.
Expand All @@ -24,6 +24,8 @@ let displaynames = require('./displaynames.js')

let langnames = require('./langnames.js')

let likely_subtags = require('./likely_subtags.js')

/**
* TODOs:
* 1. Handle other types of test cases.
Expand All @@ -38,7 +40,7 @@ let langnames = require('./langnames.js')
* Started 28-July-2022, [email protected]
*/

let doLogInput = 0;
let doLogInput = 0; // TODO: How to turn this on from command line?
let doLogOutput = 0;

// Test type support. Add new items as they are implemented
Expand All @@ -58,7 +60,8 @@ const supported_test_types = [
Symbol("decimal_fmt"),
Symbol("number_fmt"),
Symbol("display_names"),
Symbol("language_display_name")
Symbol("language_display_name"),
Symbol("local_info")
];
const supported_tests_json = {"supported_tests":
[
Expand Down Expand Up @@ -124,12 +127,12 @@ rl.on('line', function(line) {
if (line == "#VERSION") {
// JSON output of the test enviroment.
const versionJson = {'platform': 'NodeJS',
'platformVersion': process.version,
'icuVersion': process.versions.icu,
'cldrVersion': process.versions.cldr
};
'platformVersion': process.version,
'icuVersion': process.versions.icu,
'cldrVersion': process.versions.cldr
};

// TODO: Make this more specific JSON info.
// TODO: Make this more specific for JSON info.
lineOut = JSON.stringify(versionJson);
process.stdout.write(lineOut);
} else
Expand All @@ -147,12 +150,13 @@ rl.on('line', function(line) {
try {
parsedJson = JSON.parse(line);
} catch (error) {
outputLine = {'Cannot parse input line': error,
outputLine = {'error': error,
'message': 'Cannot parse input line',
'input_line': line,
"testId": testId};

// Send result to stdout for verification
jsonOut = JSON.stringify(outputLine);
const jsonOut = JSON.stringify(outputLine);
if (doLogOutput > 0) {
console.log("## ERROR " + lineId + ' ' + outputLine + ' !!!!!');
}
Expand All @@ -163,7 +167,6 @@ rl.on('line', function(line) {
console.log("#----- PARSED JSON: " + JSON.stringify(parsedJson));
}

// testId = parseJsonForTestId(parsedJson);
// Handle the string directly to call the correct function.
const test_type = parsedJson["test_type"];
if (test_type == "coll_shift_short") {
Expand All @@ -177,18 +180,23 @@ rl.on('line', function(line) {
} else
if (test_type == "language_display_name") {
outputLine = langnames.testLangNames(parsedJson);
} else
if (test_type == "likely_subtags") {
outputLine = likely_subtags.testLikelySubtags(parsedJson);
} else {
outputLine = {'error': 'unknown test type', 'testId': testId,
'unsupported_test': testId};
outputLine = {'error': 'unknown test type',
'test_type': test_type,
'unsupported_test': test_type};
}

const jsonOut = JSON.stringify(outputLine);

if ('error' in outputLine) {
// To get the attention of the driver
console.log("#!! ERROR in NODE call: " + JSON.stringify(outputLine));
console.log("#!! ERROR in NODE call: " + jsonOut);
}

// Send result to stdout for verification
jsonOut = JSON.stringify(outputLine);
process.stdout.write(jsonOut + '\n');
if (doLogOutput > 0) {
console.log("##### NODE RETURNS " + lineId + ' ' + jsonOut + ' !!!!!');
Expand Down
43 changes: 43 additions & 0 deletions executors/node/likely_subtags.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// Tests Intl Locale for minimize / maximize likely subtags.

// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale


module.exports = {
testLikelySubtags: function (json) {
const label = json['label'];
const locale = json['locale'];
let test_option;
if (json['option']) {
test_option = json['option'];
}

let return_json = {'label': label};
let intl_locale;
try {
intl_locale = new Intl.Locale(locale);
} catch (error) {
/* Something is wrong with the constructor */
return_json['error'] = 'CONSTRUCTOR: ' + error.message;
return return_json;
}

try {
let result_locale;
if (test_option === 'maximize') {
result_locale = intl_locale.maximize().baseName;
} else if (test_option === 'minimizeFavorScript' ||
test_option === 'minimize') {
result_locale = intl_locale.minimize().baseName;
} else if (test_option === 'minimizeFavorRegion') {
result_locale = intl_locale.minimizeFavorRegion().baseName;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: there is no Intl.Locale.prototype.minizeFavorRegion; this should be unsupported

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated now.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see where this is fixed but OK to fix later

} else {
return_json['error'] = 'Unknown test option = ' + test_option;
}
return_json['result'] = result_locale;
} catch (error) {
return_json['unsupported'] = 'LIKELY_SUBTAGS UNKNOWN ERROR: ' + error.message;
}
return return_json;
}
}
13 changes: 6 additions & 7 deletions generateDataAndRun.sh
Original file line number Diff line number Diff line change
Expand Up @@ -63,19 +63,19 @@ source "$HOME/.nvm/nvm.sh"
#Dart ICU73
nvm install 20.1.0
nvm use 20.1.0
python3 testdriver.py --icu_version icu73 --exec dart_web --test_type coll_shift_short --file_base ../$TEMP_DIR --per_execution 10000
python3 testdriver.py --icu_version icu73 --exec dart_web --test_type coll_shift_short number_fmt --file_base ../$TEMP_DIR --per_execution 10000
echo $?

#ICU73
nvm install 20.1.0
nvm use 20.1.0
python3 testdriver.py --icu_version icu73 --exec node --test_type coll_shift_short number_fmt lang_names --file_base ../$TEMP_DIR --per_execution 10000
python3 testdriver.py --icu_version icu73 --exec node --test_type coll_shift_short number_fmt lang_names likely_subtags --file_base ../$TEMP_DIR --per_execution 10000
echo $?

#ICU72
nvm install 18.14.2
nvm use 18.14.2
python3 testdriver.py --icu_version icu72 --exec node --test_type coll_shift_short number_fmt lang_names --file_base ../$TEMP_DIR --per_execution 10000
python3 testdriver.py --icu_version icu72 --exec node --test_type coll_shift_short number_fmt lang_names likely_subtags --file_base ../$TEMP_DIR --per_execution 10000
echo $?

#ICU71
Expand All @@ -96,9 +96,9 @@ python3 testdriver.py --icu_version icu69 --exec node --test_type coll_shift_sho
echo $?

# ICU4X testing
python3 testdriver.py --icu_version icu71 --exec rust --test_type coll_shift_short number_fmt lang_names --file_base ../$TEMP_DIR --per_execution 10000
python3 testdriver.py --icu_version icu71 --exec rust --test_type coll_shift_short number_fmt lang_names likely_subtags --file_base ../$TEMP_DIR --per_execution 10000

python3 testdriver.py --icu_version icu73 --exec rust --test_type coll_shift_short number_fmt lang_names --file_base ../$TEMP_DIR --per_execution 10000
python3 testdriver.py --icu_version icu73 --exec rust --test_type coll_shift_short number_fmt lang_names likely_subtags --file_base ../$TEMP_DIR --per_execution 10000
echo $?

# Done with test execution
Expand All @@ -111,9 +111,8 @@ popd
# Verify everything
mkdir -p $TEMP_DIR/testReports
pushd verifier
python3 verifier.py --file_base ../$TEMP_DIR --exec rust node dart_web --test_type coll_shift_short number_fmt lang_names
python3 verifier.py --file_base ../$TEMP_DIR --exec rust node dart_web --test_type coll_shift_short number_fmt lang_names likely_subtags

#python3 verifier.py --file_base ../$TEMP_DIR --exec dart_web --test_type coll_shift_short
#python3 verifier.py --file_base ../$TEMP_DIR --exec cpp--test_type coll_shift_short number_fmt lang_names
popd

Expand Down
8 changes: 8 additions & 0 deletions testdriver/datasets.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ class testType(Enum):
datetime_fmt = 'datetime_fmt'
display_names = 'display_names'
lang_names = 'lang_names'
likely_subtags = 'likely_subtags'
local_info = 'local_info'
number_fmt = 'number_fmt'

# Returns default value for a key not defined.
Expand Down Expand Up @@ -131,6 +133,12 @@ def def_value():
'lang_name_verify_file.json',
CLDRVersion.CLDR41, ICUVersion.ICU71)

testName = 'likely_subtags'
testDatasets[testName] = DataSet(testType.likely_subtags.value,
'likely_subtags_test.json',
'likely_subtags_verify.json',
CLDRVersion.CLDR43, ICUVersion.ICU73)

testName = 'number_fmt'
testDatasets[testName] = DataSet(testType.number_fmt.value,
'num_fmt_test_file.json',
Expand Down
5 changes: 3 additions & 2 deletions testdriver/ddtargs.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def __init__(self):
self.exec_mode = 'one_test' # Default. 'multi_test

type_options = ['coll_shift_short', 'decimal_fmt', 'display_names',
'number_fmt', 'lang_names', 'ALL']
'number_fmt', 'lang_names', 'likely_subtags', 'ALL']

class DdtArgs():
def __init__(self, args):
Expand Down Expand Up @@ -145,7 +145,8 @@ def argsTestData():
['--test_type', 'coll_shift_short'],
['--test_type', 'coll_shift_short', '-t', 'decimal_fmt'],
['--test_type', 'coll_shift_short', '--test_type', 'decimal_fmt', 'number_fmt', 'display_names',
'lang_names'],
'lang_names',
'likely_subtags'],

['--test', 'coll_shift_short', 'ALL', 'decimal_fmt'],

Expand Down
7 changes: 4 additions & 3 deletions testdriver/testplan.py
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ def process_batch_of_tests(self, tests_to_send):
logging.info('#### DEBUG OUTPUT = %s', item)

# Process some types of errors
if item[1:3] == "!!":
if item[1:3] == "!!" and self.debug > 1:
logging.warning(" !!!!!!!!!!!!!!!!! ERROR: %s", item)
# Extract the message and check if we continue or not.
json_start = item.index('{')
Expand All @@ -426,8 +426,9 @@ def process_batch_of_tests(self, tests_to_send):
json_out = json.loads(item)
batch_out.append(json_out)
except BaseException as error:
logging.warning(' && Item %s. Error in= %s. Received (%d): >%s<',
index, error, len(item), item)
if self.debug > 1:
logging.warning(' && Item %s. Error in= %s. Received (%d): >%s<',
index, error, len(item), item)
index += 1

return batch_out
Expand Down
Loading
Loading