From a8e6f7b9a32f3cbb402e343a4fd5a34c80dc20fb Mon Sep 17 00:00:00 2001 From: Nick Hall Date: Thu, 23 Feb 2017 18:43:20 +0000 Subject: [PATCH] Use current environment and executable in process The GRAMPSHOME environment variable is not unset after the gen/utils/test/file_test unit test. This caused the Gramps process to fail with an environment error. --- gramps/plugins/export/test/exportvcard_test.py | 9 ++++++--- gramps/plugins/importer/test/importvcard_test.py | 14 +++++++++----- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/gramps/plugins/export/test/exportvcard_test.py b/gramps/plugins/export/test/exportvcard_test.py index 5363bbd0b..03cea0ead 100644 --- a/gramps/plugins/export/test/exportvcard_test.py +++ b/gramps/plugins/export/test/exportvcard_test.py @@ -24,6 +24,7 @@ Unittest for export to VCard import unittest import time import subprocess +import sys import os import xml.etree.ElementTree as ET @@ -70,12 +71,14 @@ class VCardCheck(unittest.TestCase): if debug: print(ET.tostring(input_doc)) - process = subprocess.Popen('python Gramps.py ' - '-i - -f gramps -e - -f vcf', + pyexec = sys.executable + gcmd = 'Gramps.py -i - -f gramps -e - -f vcf' + process = subprocess.Popen('%s %s' % (pyexec, gcmd), stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, - shell=True) + shell=True, + env=os.environ) input_str = (self.header.encode('utf-8') + ET.tostring(input_doc, encoding='utf-8')) result_str, err_str = process.communicate(input_str) diff --git a/gramps/plugins/importer/test/importvcard_test.py b/gramps/plugins/importer/test/importvcard_test.py index 364a0a851..509865030 100644 --- a/gramps/plugins/importer/test/importvcard_test.py +++ b/gramps/plugins/importer/test/importvcard_test.py @@ -25,6 +25,8 @@ Unittest of import of VCard # in case of a failing test, add True as last parameter to do_case to see the output. import unittest +import sys +import os import time import subprocess import xml.etree.ElementTree as ET @@ -75,14 +77,16 @@ class VCardCheck(unittest.TestCase): def do_case(self, input_str, expect_doc, debug=False): if debug: print(input_str) - - process = subprocess.Popen('python3 Gramps.py -d .Date -d .ImportVCard ' - '--config=preferences.eprefix:DEFAULT ' - '-i - -f vcf -e - -f gramps', + pyexec = sys.executable + gcmd = ('Gramps.py -d .Date -d .ImportVCard ' + '--config=preferences.eprefix:DEFAULT ' + '-i - -f vcf -e - -f gramps') + process = subprocess.Popen('%s %s' % (pyexec, gcmd), stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, - shell=True) + shell=True, + env=os.environ) result_str, err_str = process.communicate(input_str.encode("utf-8")) if debug: print(err_str)