this repo has no description
at trunk 51 lines 1.1 kB view raw
1// Copyright (c) Facebook, Inc. and its affiliates. (http://www.facebook.com) 2#include "capi-fixture.h" 3 4#include <clocale> 5 6#include "Python.h" 7 8namespace py { 9namespace testing { 10 11const char* argv0; 12 13void resetPythonEnv() { 14 // TODO(T70174461): Replace with config API when we upgraded to 3.8 15 Py_BytesWarningFlag = 0; 16 Py_DebugFlag = 0; 17 Py_DontWriteBytecodeFlag = 0; 18 Py_FrozenFlag = 0; 19 Py_HashRandomizationFlag = 0; 20 Py_IgnoreEnvironmentFlag = 0; 21 Py_InspectFlag = 0; 22 Py_InteractiveFlag = 0; 23 Py_IsolatedFlag = 0; 24 Py_NoSiteFlag = 1; 25 Py_NoUserSiteDirectory = 0; 26 Py_OptimizeFlag = 0; 27 Py_QuietFlag = 0; 28 Py_UTF8Mode = 1; 29 Py_UnbufferedStdioFlag = 0; 30 Py_VerboseFlag = 0; 31 Py_SetPath(nullptr); 32 std::setlocale(LC_CTYPE, ""); 33 wchar_t* argv0_w = Py_DecodeLocale(argv0, nullptr); 34 Py_SetProgramName(argv0_w); 35 PyMem_RawFree(argv0_w); 36 std::setlocale(LC_CTYPE, "en_US.UTF-8"); 37} 38 39void ExtensionApi::SetUp() { 40 resetPythonEnv(); 41 Py_Initialize(); 42} 43 44void ExtensionApi::TearDown() { 45 PyErr_Clear(); 46 Py_FinalizeEx(); 47 std::setlocale(LC_CTYPE, "C"); 48} 49 50} // namespace testing 51} // namespace py