Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions avogadro/qtgui/pythonscript.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <QtCore/QFileInfo>
#include <QtCore/QLocale>
#include <QtCore/QProcess>
#include <QtCore/QProcessEnvironment>
#include <QtCore/QSettings>
#include <QtCore/QStandardPaths>

Expand Down Expand Up @@ -126,6 +127,12 @@ void PythonScript::setDefaultPythonInterpreter()

QString PythonScript::resolveCommand(QStringList& realArgs, QProcess& proc)
{
#ifdef Q_OS_WIN
QProcessEnvironment environment = QProcessEnvironment::systemEnvironment();
environment.insert(QStringLiteral("PYTHONUTF8"), QStringLiteral("1"));
proc.setProcessEnvironment(environment);
#endif

// --- Package mode: pixi run <command> <identifier> [args] ---
if (m_packageMode) {
if (m_pixi.isEmpty()) {
Expand Down
6 changes: 6 additions & 0 deletions tests/qtgui/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ set(tests
RWMolecule
)

if(Python3_EXECUTABLE)
list(APPEND tests
PythonScript
)
endif()

if (BUILD_MOLEQUEUE)
# Pull in MoleQueue
find_package(MoleQueue REQUIRED NO_MODULE)
Expand Down
32 changes: 32 additions & 0 deletions tests/qtgui/pythonscripttest.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/******************************************************************************
This source file is part of the Avogadro project.
This source code is released under the 3-Clause BSD License, (see "LICENSE").
******************************************************************************/

#include <gtest/gtest.h>

#include <avogadro/qtgui/pythonscript.h>

#include <QtCore/QFile>
#include <QtCore/QTemporaryDir>

using Avogadro::QtGui::PythonScript;

TEST(PythonScriptTest, WindowsUsesUtf8Mode)
{
#ifndef Q_OS_WIN
GTEST_SKIP() << "PYTHONUTF8 is only set on Windows.";
#else
QTemporaryDir temporaryDirectory;
ASSERT_TRUE(temporaryDirectory.isValid());

QFile script(temporaryDirectory.filePath("utf8_mode.py"));
ASSERT_TRUE(script.open(QIODevice::WriteOnly | QIODevice::Text));
const QByteArray source("import sys\nprint(sys.flags.utf8_mode)\n");
ASSERT_EQ(script.write(source), source.size());
script.close();

PythonScript pythonScript(script.fileName());
EXPECT_EQ(pythonScript.execute({}).trimmed(), QByteArray("1"));
#endif
}
Loading