Skip to content

Commit

Permalink
testing: python3 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
jbohren committed Sep 23, 2014
1 parent a69725f commit 8475598
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 20 deletions.
6 changes: 3 additions & 3 deletions catkin_tools/runner/run_unix.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
def process_incomming_lines(lines, left_over):
if not lines:
return None, left_over
if lines[-1].rstrip() != lines[-1]:
if str(lines[-1]).endswith('\n'):
data = b''.join(lines)
left_over = b''
else:
Expand Down Expand Up @@ -64,8 +64,8 @@ def run_command(cmd, cwd=None):
data, left_over = process_incomming_lines(lines, left_over)
if data is None:
continue
yield data
yield str(data)

# Done
os.close(master)
yield p.returncode
yield int(p.returncode)
30 changes: 13 additions & 17 deletions tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ class temporary_directory(object):

def __init__(self, prefix=''):
self.prefix = prefix
self.delete = False

def __enter__(self):
self.original_cwd = os.getcwd()
Expand All @@ -101,7 +102,8 @@ def __enter__(self):
return self.temp_path

def __exit__(self, exc_type, exc_value, traceback):
if self.temp_path and os.path.exists(self.temp_path):
if self.delete and self.temp_path and os.path.exists(self.temp_path):
print('Deleting temporary testind directory: %s' % self.temp_path)
shutil.rmtree(self.temp_path)
if self.original_cwd and os.path.exists(self.original_cwd):
os.chdir(self.original_cwd)
Expand Down Expand Up @@ -139,22 +141,16 @@ def run(args, **kwargs):
Call to Popen, returns (errcode, stdout, stderr)
"""
print("run:", args)
with tempfile.NamedTemporaryFile(mode='w+') as temp_buffer:
p = subprocess.Popen(
args,
stdout=temp_buffer,
stderr=subprocess.STDOUT,
universal_newlines=True,
cwd=kwargs.get('cwd', os.getcwd()))
print("P==", p.__dict__)
print("Dumping stdout to: "+ temp_buffer.name)
p.wait()
temp_buffer.seek(0)
stdout = temp_buffer.read()

return (p.returncode, stdout, '')

return (None, None, None)
p = subprocess.Popen(
args,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
universal_newlines=True,
cwd=kwargs.get('cwd', os.getcwd()))
print("P==", p.__dict__)
(stdout, stderr) = p.communicate()

return (p.returncode, stdout, stderr)


def assert_cmd_success(cmd, **kwargs):
Expand Down

0 comments on commit 8475598

Please sign in to comment.