Skip to content

Commit

Permalink
PROTON-2413: [Python] set PATH in example test runner
Browse files Browse the repository at this point in the history
Previously the test runner assumed it could find the examples on the
path. This meant that the environment running the examples would have to
set up the path correctly. This is unnecessary as they are all in the
same directory as the test runner itself.
  • Loading branch information
astitcher committed Aug 5, 2021
1 parent 38e1768 commit 052cf28
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions python/examples/test_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
# under the License.
#

import re
import os
import subprocess
import time
import unittest
Expand All @@ -27,12 +27,16 @@ class Popen(subprocess.Popen):

# We always use these options
def __init__(self, args, **kwargs):
# Add the module directory to the path to be able to find the examples
path = f"{os.path.dirname(__file__)}{os.pathsep}{os.environ['PATH']}"
super(Popen, self).\
__init__(args,
shell=False,
stderr=subprocess.STDOUT,
stdout=subprocess.PIPE,
universal_newlines=True, **kwargs)
universal_newlines=True,
env={'PATH': path},
**kwargs)


# Like subprocess.run with our defaults but returning the Popen object
Expand All @@ -41,6 +45,13 @@ def run(args, **kwargs):
p.wait()
return p


def check_call(args, **kwargs):
# Add the module directory to the path to be able to find the examples
path = f"{os.path.dirname(__file__)}{os.pathsep}{os.environ['PATH']}"
return subprocess.check_call(args, env={'PATH': path}, **kwargs)


class ExamplesTest(unittest.TestCase):
def test_helloworld(self, example="helloworld.py"):
with run([example]) as p:
Expand Down Expand Up @@ -101,8 +112,8 @@ def test_sync_client_server_direct(self):
def test_db_send_recv(self):
self.maxDiff = None
# setup databases
subprocess.check_call(['db_ctrl.py', 'init', './src_db'])
subprocess.check_call(['db_ctrl.py', 'init', './dst_db'])
check_call(['db_ctrl.py', 'init', './src_db'])
check_call(['db_ctrl.py', 'init', './dst_db'])
with Popen(['db_ctrl.py', 'insert', './src_db'], stdin=subprocess.PIPE) as fill:
for i in range(100):
fill.stdin.write("Message-%i\n" % (i + 1))
Expand Down

0 comments on commit 052cf28

Please sign in to comment.