mirror of https://github.com/KLayout/klayout.git
Using pipes instead of QProcess for pymod tests, enable pipes on Windows (needs testing)
This commit is contained in:
parent
642fb4270b
commit
ad7a9836b0
|
|
@ -31,38 +31,30 @@
|
|||
#define _STRINGIFY(s) #s
|
||||
|
||||
#include "tlUnitTest.h"
|
||||
#include "tlStream.h"
|
||||
|
||||
#if defined(HAVE_QT)
|
||||
# include <QProcess>
|
||||
# include <QProcessEnvironment>
|
||||
#endif
|
||||
|
||||
int run_pymodtest (tl::TestBase * /*_this*/, const std::string &fn)
|
||||
int run_pymodtest (tl::TestBase *_this, const std::string &fn)
|
||||
{
|
||||
#if defined(HAVE_QT)
|
||||
QProcess process;
|
||||
process.setProcessChannelMode (QProcess::MergedChannels);
|
||||
|
||||
QStringList args;
|
||||
static std::string pypath;
|
||||
pypath = "PYTHONPATH=";
|
||||
pypath += STRINGIFY (PYTHONPATH);
|
||||
putenv ((char *) pypath.c_str ());
|
||||
|
||||
std::string fp (tl::testsrc ());
|
||||
fp += "/testdata/pymod/";
|
||||
fp += fn;
|
||||
args << tl::to_qstring (fp);
|
||||
|
||||
QProcessEnvironment env = QProcessEnvironment::systemEnvironment ();
|
||||
env.insert("PYTHONPATH", STRINGIFY (PYTHONPATH));
|
||||
process.setProcessEnvironment(env);
|
||||
std::string text;
|
||||
{
|
||||
tl::InputPipe pipe (std::string (STRINGIFY (PYTHON)) + " " + fp + " 2>&1");
|
||||
tl::InputStream is (pipe);
|
||||
text = is.read_all ();
|
||||
}
|
||||
|
||||
process.start (tl::to_qstring (STRINGIFY (PYTHON)), args);
|
||||
process.waitForFinished (-1);
|
||||
tl::info << text;
|
||||
EXPECT_EQ (text.find ("OK") != std::string::npos, true);
|
||||
|
||||
tl::info << process.readAll ().constData ();
|
||||
|
||||
return process.exitCode ();
|
||||
#else
|
||||
return 1; // TODO: provide a Qt-less version
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
#define PYMODTEST(n, file) \
|
||||
|
|
|
|||
|
|
@ -861,7 +861,91 @@ OutputZLibFile::write (const char *b, size_t n)
|
|||
}
|
||||
}
|
||||
|
||||
#ifndef _WIN32 // not available on Windows
|
||||
#if defined(_WIN32)
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
// InputPipe delegate implementation
|
||||
|
||||
InputPipe::InputPipe (const std::string &path)
|
||||
: m_file (NULL)
|
||||
{
|
||||
std::wstring wpath = tl::to_wstring (path);
|
||||
m_source = path;
|
||||
m_file = _wpopen (wpath.c_str (), "r");
|
||||
if (m_file == NULL) {
|
||||
throw FilePOpenErrorException (m_source, errno);
|
||||
}
|
||||
}
|
||||
|
||||
InputPipe::~InputPipe ()
|
||||
{
|
||||
close ();
|
||||
}
|
||||
|
||||
void
|
||||
InputPipe::close ()
|
||||
{
|
||||
if (m_file != NULL) {
|
||||
fclose (m_file);
|
||||
m_file = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
size_t
|
||||
InputPipe::read (char *b, size_t n)
|
||||
{
|
||||
tl_assert (m_file != NULL);
|
||||
size_t ret = fread (b, 1, n, m_file);
|
||||
if (ret < n) {
|
||||
if (ferror (m_file)) {
|
||||
throw FilePReadErrorException (m_source, ferror (m_file));
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
void
|
||||
InputPipe::reset ()
|
||||
{
|
||||
throw tl::Exception (tl::to_string (tr ("'reset' is not supported on pipeline input files")));
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
// OutputPipe delegate implementation
|
||||
|
||||
OutputPipe::OutputPipe (const std::string &path)
|
||||
: m_file (NULL)
|
||||
{
|
||||
std::wstring wpath = tl::to_wstring (path);
|
||||
m_source = path;
|
||||
m_file = _wpopen (wpath.c_str (), "w");
|
||||
if (m_file == NULL) {
|
||||
throw FilePOpenErrorException (m_source, errno);
|
||||
}
|
||||
}
|
||||
|
||||
OutputPipe::~OutputPipe ()
|
||||
{
|
||||
if (m_file != NULL) {
|
||||
fclose (m_file);
|
||||
m_file = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
OutputPipe::write (const char *b, size_t n)
|
||||
{
|
||||
tl_assert (m_file != NULL);
|
||||
size_t ret = fwrite (b, 1, n, m_file);
|
||||
if (ret < n) {
|
||||
if (ferror (m_file)) {
|
||||
throw FilePWriteErrorException (m_source, ferror (m_file));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
// InputPipe delegate implementation
|
||||
|
|
@ -943,58 +1027,6 @@ OutputPipe::write (const char *b, size_t n)
|
|||
}
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
// InputPipe delegate implementation
|
||||
|
||||
InputPipe::InputPipe (const std::string & /*path*/)
|
||||
: m_file (NULL)
|
||||
{
|
||||
// TODO: emulate?
|
||||
}
|
||||
|
||||
InputPipe::~InputPipe ()
|
||||
{
|
||||
}
|
||||
|
||||
size_t
|
||||
InputPipe::read (char * /*b*/, size_t /*n*/)
|
||||
{
|
||||
throw tl::Exception (tl::to_string (tr ("pipeline input files not available on Windows")));
|
||||
}
|
||||
|
||||
void
|
||||
InputPipe::reset ()
|
||||
{
|
||||
throw tl::Exception (tl::to_string (tr ("pipeline input files not available on Windows")));
|
||||
}
|
||||
|
||||
void
|
||||
InputPipe::close ()
|
||||
{
|
||||
throw tl::Exception (tl::to_string (tr ("pipeline input files not available on Windows")));
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
// OutputPipe delegate implementation
|
||||
|
||||
OutputPipe::OutputPipe (const std::string & /*path*/)
|
||||
: m_file (NULL)
|
||||
{
|
||||
// TODO: emulate?
|
||||
}
|
||||
|
||||
OutputPipe::~OutputPipe ()
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
OutputPipe::write (const char * /*b*/, size_t /*n*/)
|
||||
{
|
||||
throw tl::Exception (tl::to_string (tr ("pipeline input files not available on Windows")));
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
|
|
|
|||
|
|
@ -171,7 +171,7 @@ private:
|
|||
*
|
||||
* Implements the reader for a zlib stream
|
||||
*/
|
||||
class InputZLibFile
|
||||
class TL_PUBLIC InputZLibFile
|
||||
: public InputStreamBase
|
||||
{
|
||||
public:
|
||||
|
|
@ -224,7 +224,7 @@ private:
|
|||
*
|
||||
* Implements the reader for ordinary files.
|
||||
*/
|
||||
class InputFile
|
||||
class TL_PUBLIC InputFile
|
||||
: public InputStreamBase
|
||||
{
|
||||
public:
|
||||
|
|
@ -272,7 +272,7 @@ private:
|
|||
*
|
||||
* Implements the reader for pipe streams
|
||||
*/
|
||||
class InputPipe
|
||||
class TL_PUBLIC InputPipe
|
||||
: public InputStreamBase
|
||||
{
|
||||
public:
|
||||
|
|
|
|||
Loading…
Reference in New Issue