Skip to content

Commit

Permalink
use utf8 decoding; fix "installing eggs" bug
Browse files Browse the repository at this point in the history
  • Loading branch information
jborbely committed Aug 29, 2017
1 parent 32826f1 commit 17f3064
Showing 1 changed file with 26 additions and 14 deletions.
40 changes: 26 additions & 14 deletions test_envs.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ def color_print(line):
print(line[:-6] + colorama.Fore.GREEN + 'PASSED')
elif line.endswith('FAILED'):
print(line[:-6] + colorama.Fore.RED + 'FAILED')
elif 'FAILURES' in line:
print(colorama.Fore.RED + colorama.Style.BRIGHT + line)
elif line.endswith('ERROR'):
print(line[:-5] + colorama.Fore.RED + 'ERROR')
elif line.startswith('___'):
Expand All @@ -72,6 +74,10 @@ def color_print(line):
print(colorama.Fore.GREEN + colorama.Style.BRIGHT + line)
elif line.startswith('All tests passed'):
print(colorama.Fore.GREEN + colorama.Style.BRIGHT + line)
elif line.startswith('Install'):
print(colorama.Fore.CYAN + colorama.Style.BRIGHT + line)
elif line.startswith('***** '):
print(colorama.Fore.BLUE + colorama.Style.BRIGHT + line)
else:
print(line)
else:
Expand All @@ -85,7 +91,7 @@ def color_print(line):

# get a list of all conda envs
p = Popen(['conda', 'info', '--envs'], stdout=PIPE)
all_envs = [item.decode() for item in p.communicate()[0].split() if 'envs' in item.decode()]
all_envs = [item.decode('utf-8') for item in p.communicate()[0].split() if 'envs' in item.decode('utf-8')]

# perform the include filter
envs = [] if args.include else all_envs
Expand Down Expand Up @@ -116,24 +122,30 @@ def color_print(line):
for env in envs:

py_exe = os.path.join(env, path, 'python')
print('Testing with ' + py_exe)
color_print('***** Testing with {} *****'.format(py_exe))

proc = Popen([py_exe, 'setup.py', 'test'], stdout=PIPE, stderr=PIPE)

show = False
summary = ''
while True:
stdout = proc.stdout.readline().decode().strip()
if stdout == '' and proc.poll() is not None:
stdout = proc.stdout.readline().decode('utf-8').strip()
if stdout.startswith('Reading'):
color_print('Installing egg for' + stdout.split('Reading')[1])
continue
if stdout.startswith('Installed'):
color_print(stdout)
continue
if not stdout and proc.poll() is not None:
break
if stdout.startswith('collect') and 'error' in stdout: # errors during the "collecting..."
summary += stdout
success = False
break
if 'FAILURES' in summary:
summary += stdout
success = False
break
if not stdout:
# if there were any "import exceptions" and pytest could not
# start properly then the output will be empty
stderr = proc.stderr.read().decode()
if stderr.startswith('Traceback'):
print(stderr)
success = False
break
if stdout.startswith('='):
show = True
if show:
Expand All @@ -142,12 +154,12 @@ def color_print(line):
if ' seconds =' in stdout:
show = False # once the test is finished a bunch of blank lines can be printed -- ignore these lines

stdout = proc.stdout.read().decode().strip()
stdout = proc.stdout.read().decode('utf-8').strip()
for item in stdout.split('\n'):
color_print(item)

summary += stdout
if 'FAILURES' in summary or 'ERRORS' in summary or 'FAILED' in summary or 'ERROR' in summary:
if 'FAILURES' in summary or 'ERROR' in summary or 'FAILED' in summary or 'failed' in summary:
success = False

if not success:
Expand Down

0 comments on commit 17f3064

Please sign in to comment.