2323
2424#include < gtest/gtest.h>
2525
26+ #if __has_include(<PythonStandardLibrary.h>)
27+ #define YUP_HAS_EMBEDDED_PYTHON_STANDARD_LIBRARY 1
2628#include < PythonStandardLibrary.h>
29+ #endif
2730
2831using namespace yup ;
2932
@@ -42,13 +45,17 @@ class ScriptPythonTest : public ::testing::Test
4245
4346 void SetUp () override
4447 {
48+ #if YUP_HAS_EMBEDDED_PYTHON_STANDARD_LIBRARY
4549 engine = std::make_unique<ScriptEngine> (ScriptEngine::prepareScriptingHome (
4650 YUPApplication::getInstance ()->getApplicationName (),
4751 File::getSpecialLocation (File::tempDirectory),
4852 [] (const char *) -> MemoryBlock
4953 {
5054 return { PythonStandardLibrary_data, PythonStandardLibrary_size };
5155 }));
56+ #else
57+ engine = std::make_unique<ScriptEngine>();
58+ #endif
5259 }
5360
5461 void TearDown () override
@@ -67,6 +74,25 @@ TEST_F (ScriptPythonTest, RunPythonTests)
6774 currentWorkingDirectory.setAsCurrentWorkingDirectory ();
6875 });
6976
77+ auto scriptingVersion = engine->getScriptingVersion ();
78+ auto scriptingVersionCompact = scriptingVersion.upToLastOccurrenceOf (" ." , false , false );
79+
80+ auto scriptingHome = engine->getScriptingHome ();
81+ if (scriptingHome == File ())
82+ {
83+ scriptingHome = File::getSpecialLocation (File::userHomeDirectory).getChildFile (" yup_python" );
84+ scriptingHome.createDirectory ();
85+
86+ auto binDirectory = scriptingHome.getChildFile (" bin" );
87+ binDirectory.createDirectory ();
88+
89+ auto sitePackages = scriptingHome
90+ .getChildFile (" lib" )
91+ .getChildFile (" python" + scriptingVersionCompact)
92+ .getChildFile (" site-packages" );
93+ sitePackages.createDirectory ();
94+ }
95+
7096 auto baseFolder = getPytestTestFolder ().getParentDirectory ();
7197 baseFolder.setAsCurrentWorkingDirectory ();
7298
@@ -91,8 +117,8 @@ TEST_F (ScriptPythonTest, RunPythonTests)
91117
92118 script = script
93119 .dedentLines ()
94- .replace (" {{version}}" , engine-> getScriptingVersion (). upToLastOccurrenceOf ( " . " , false , false ) )
95- .replace (" {{root_path}}" , engine-> getScriptingHome () .getFullPathName ())
120+ .replace (" {{version}}" , scriptingVersionCompact )
121+ .replace (" {{root_path}}" , scriptingHome .getFullPathName ())
96122 .replace (" {{test_path}}" , getPytestTestFolder ().getFullPathName ());
97123
98124 auto result = engine->runScript (script);
0 commit comments