From d4c714c400a446d1bcba258da92be67f3444f897 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 15 Aug 2017 13:49:43 +0200 Subject: [PATCH] Python: fix up testing script - Didn't run at all (at least since v3.1) because of mismatch between GlobalStorage constructor arguments and use; special-case None in the C++ code to allocate a new GlobalStorage object. --- src/libcalamares/GlobalStorage.cpp | 9 ++++++++- src/modules/testmodule.py | 5 ++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/libcalamares/GlobalStorage.cpp b/src/libcalamares/GlobalStorage.cpp index 3fc7d0fa9..e56a241e9 100644 --- a/src/libcalamares/GlobalStorage.cpp +++ b/src/libcalamares/GlobalStorage.cpp @@ -18,12 +18,14 @@ */ #include "GlobalStorage.h" +#include "JobQueue.h" #include "utils/Logger.h" #ifdef WITH_PYTHON #include "PythonHelper.h" + #undef slots #include #include @@ -99,8 +101,13 @@ GlobalStorage::debugDump() const namespace CalamaresPython { +// The special handling for nullptr is only for the testing +// script for the python bindings, which passes in None; +// normal use will have a GlobalStorage from JobQueue::instance() +// passed in. Testing use will leak the allocated GlobalStorage +// object, but that's OK for testing. GlobalStoragePythonWrapper::GlobalStoragePythonWrapper( Calamares::GlobalStorage* gs ) - : m_gs( gs ) + : m_gs( gs ? gs : new Calamares::GlobalStorage ) {} bool diff --git a/src/modules/testmodule.py b/src/modules/testmodule.py index 9c3e57318..da852f814 100755 --- a/src/modules/testmodule.py +++ b/src/modules/testmodule.py @@ -4,6 +4,7 @@ # === This file is part of Calamares - === # # Copyright 2014, Teo Mrnjavac +# Copyright 2017, Adriaan de Groot # # Calamares is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -81,7 +82,9 @@ def main(): print("Only Python jobs can be tested.") return 1 - libcalamares.globalstorage = libcalamares.GlobalStorage() + # Parameter None creates a new, empty GlobalStorage + libcalamares.globalstorage = libcalamares.GlobalStorage(None) + libcalamares.globalstorage.insert("testing", True) # if a file for simulating globalStorage contents is provided, load it if args.globalstorage_yaml: