plugins/python/regress/testhelpers.c: replace fromisoformat
fromisoformat is only supported from python >=3.7
This commit is contained in:

committed by
Todd C. Miller

parent
efa97b5b97
commit
8395a20a20
@@ -259,9 +259,10 @@ mock_python_datetime_now(const char *plugin_name, const char *date_str)
|
|||||||
char *cmd = NULL;
|
char *cmd = NULL;
|
||||||
asprintf(&cmd, "import %s\n" // the plugin has its own submodule
|
asprintf(&cmd, "import %s\n" // the plugin has its own submodule
|
||||||
"from datetime import datetime\n" // store the real datetime
|
"from datetime import datetime\n" // store the real datetime
|
||||||
|
"import time\n"
|
||||||
"from unittest.mock import Mock\n"
|
"from unittest.mock import Mock\n"
|
||||||
"%s.datetime = Mock()\n" // replace plugin's datetime
|
"%s.datetime = Mock()\n" // replace plugin's datetime
|
||||||
"%s.datetime.now = lambda: datetime.fromisoformat('%s')\n",
|
"%s.datetime.now = lambda: datetime.fromtimestamp(time.mktime(time.strptime('%s', '%%Y-%%m-%%dT%%H:%%M:%%S')))\n",
|
||||||
plugin_name, plugin_name, plugin_name, date_str);
|
plugin_name, plugin_name, plugin_name, date_str);
|
||||||
VERIFY_PTR_NE(cmd, NULL);
|
VERIFY_PTR_NE(cmd, NULL);
|
||||||
VERIFY_INT(PyRun_SimpleString(cmd), 0);
|
VERIFY_INT(PyRun_SimpleString(cmd), 0);
|
||||||
|
Reference in New Issue
Block a user