mirror of
https://github.com/facebook/sapling.git
synced 2024-12-28 07:33:10 +03:00
py3: fix Mononoke Python 3 test failures
Summary: Fixes a few issues with Mononoke tests in Python 3. 1. We need to use different APIs to account for the unicode vs bytes difference for path hash encoding. 2. We need to set the language environment for tests that create utf8 file paths. 3. We need the redaction message and marker to be bytes. Oddly this test still fails with jq CLI errors, but it makes it past the original error. Reviewed By: quark-zju Differential Revision: D23582976 fbshipit-source-id: 44959903aedc5dc9c492ec09a17b9c8e3bdf9457
This commit is contained in:
parent
ed4021b8e3
commit
f5a2347fbb
@ -45,14 +45,7 @@ DISABLE_ALL_NETWORK_ACCESS_SKIPLIST: Set[str] = {
|
||||
"test-commitcloud-reversefiller.t",
|
||||
}
|
||||
|
||||
PY3_SKIPLIST: Set[str] = {
|
||||
"test-hook-limit-path-length.t",
|
||||
"test-hook-no-bad-filenames.t",
|
||||
"test-hook-no-insecure-filenames.t",
|
||||
"test-large-path-and-content.t",
|
||||
"test-push-redirector-sync-job.t",
|
||||
"test-redaction.t",
|
||||
}
|
||||
PY3_SKIPLIST: Set[str] = set()
|
||||
|
||||
|
||||
def is_mode_opt_buck_binary():
|
||||
|
@ -34,9 +34,9 @@ METAKEYFLAG = "f" # revlog flag
|
||||
METAKEYSIZE = "s" # full rawtext size
|
||||
|
||||
# Tombstone string returned as content for redacted files
|
||||
REDACTED_CONTENT = "PoUOK1GkdH6Xtx5j9WKYew3dZXspyfkahcNkhV6MJ4rhyNICTvX0nxmbCImFoT0oHAF9ivWGaC6ByswQZUgf1nlyxcDcahHknJS15Vl9Lvc4NokYhMg0mV1rapq1a4bhNoUI9EWTBiAkYmkadkO3YQXV0TAjyhUQWxxLVskjOwiiFPdL1l1pdYYCLTE3CpgOoxQV3EPVxGUPh1FGfk7F9Myv22qN1sUPSNN4h3IFfm2NNPRFgWPDsqAcaQ7BUSKa\n"
|
||||
REDACTED_CONTENT = b"PoUOK1GkdH6Xtx5j9WKYew3dZXspyfkahcNkhV6MJ4rhyNICTvX0nxmbCImFoT0oHAF9ivWGaC6ByswQZUgf1nlyxcDcahHknJS15Vl9Lvc4NokYhMg0mV1rapq1a4bhNoUI9EWTBiAkYmkadkO3YQXV0TAjyhUQWxxLVskjOwiiFPdL1l1pdYYCLTE3CpgOoxQV3EPVxGUPh1FGfk7F9Myv22qN1sUPSNN4h3IFfm2NNPRFgWPDsqAcaQ7BUSKa\n"
|
||||
# Message shown to the user when file is redacted
|
||||
REDACTED_MESSAGE = "This version of the file is redacted and you are not allowed to access it. Update or rebase to a newer commit.\n"
|
||||
REDACTED_MESSAGE = b"This version of the file is redacted and you are not allowed to access it. Update or rebase to a newer commit.\n"
|
||||
|
||||
|
||||
def getunits(category):
|
||||
|
@ -686,13 +686,7 @@ static int sha1hash(char hash[20], const char* str, Py_ssize_t len) {
|
||||
PyObject *shaobj, *hashobj;
|
||||
|
||||
if (shafunc == NULL) {
|
||||
PyObject *hashlib, *name = PyBytes_FromString("hashlib");
|
||||
|
||||
if (name == NULL)
|
||||
return -1;
|
||||
|
||||
hashlib = PyImport_Import(name);
|
||||
Py_DECREF(name);
|
||||
PyObject* hashlib = PyImport_ImportModule("hashlib");
|
||||
|
||||
if (hashlib == NULL) {
|
||||
PyErr_SetString(PyExc_ImportError, "hashlib");
|
||||
@ -710,10 +704,15 @@ static int sha1hash(char hash[20], const char* str, Py_ssize_t len) {
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef IS_PY3K
|
||||
shaobj = PyObject_CallFunction(shafunc, "y#", str, len);
|
||||
#else
|
||||
shaobj = PyObject_CallFunction(shafunc, "s#", str, len);
|
||||
#endif
|
||||
|
||||
if (shaobj == NULL)
|
||||
if (shaobj == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
hashobj = PyObject_CallMethod(shaobj, "digest", "");
|
||||
Py_DECREF(shaobj);
|
||||
@ -802,8 +801,9 @@ PyObject* pathencode(PyObject* self, PyObject* args) {
|
||||
basicencode(PyBytes_AS_STRING(newobj), newlen, path, len + 1);
|
||||
}
|
||||
#endif
|
||||
} else
|
||||
} else {
|
||||
newobj = hashencode(path, len + 1);
|
||||
}
|
||||
|
||||
return newobj;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user