Skip to content

Commit

Permalink
Enhanced the ui_automation.py coverage. Also excluded some code I don…
Browse files Browse the repository at this point in the history
…'t want to test.
  • Loading branch information
set-soft committed May 5, 2020
1 parent c714812 commit 2d76118
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 25 deletions.
10 changes: 8 additions & 2 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
[run]
source =
./kicad_auto
./src
kicad_auto
src

[report]
exclude_lines =
pragma: no cover
raise RuntimeError

39 changes: 20 additions & 19 deletions kicad_auto/ui_automation.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,18 @@


class PopenContext(subprocess.Popen):
def __enter__(self):
return self

def __exit__(self, type, value, traceback):
# Note: currently we don't communicate with the child so these cases are never used.
# I keep them in case they are needed, but excluded from the coverage.
# Also note that closing stdin needs extra handling, implemented in the parent class
# but not here.
if self.stdout:
self.stdout.close()
self.stdout.close() # pragma: no cover
if self.stderr:
self.stderr.close()
self.stderr.close() # pragma: no cover
if self.stdin:
self.stdin.close()
self.stdin.close() # pragma: no cover
if type:
self.terminate()
# Wait for the process to terminate, to avoid zombies.
Expand All @@ -58,9 +60,9 @@ def wait_xserver():
logger.debug('Waiting for virtual X server ...')
if shutil.which('setxkbmap'):
cmd = ['setxkbmap', '-query']
elif shutil.which('setxkbmap'):
elif shutil.which('setxkbmap'): # pragma: no cover
cmd = ['xset', 'q']
else:
else: # pragma: no cover
cmd = ['ls']
logger.warning('No setxkbmap nor xset available, unable to verify if X is running')
for i in range(int(timeout/DELAY)):
Expand All @@ -81,16 +83,15 @@ def recorded_xvfb(video_dir, video_name, **xvfb_args):
video_filename = os.path.join(video_dir, video_name)
with Xvfb(**xvfb_args):
wait_xserver()
fnull = open(os.devnull, 'w')
logger.debug('Recording session to %s', video_filename)
with PopenContext(['recordmydesktop',
'--overwrite',
'--no-sound',
'--no-frame',
'--on-the-fly-encoding',
'-o', video_filename],
stdout=fnull,
stderr=subprocess.STDOUT,
stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL,
close_fds=True) as screencast_proc:
yield
screencast_proc.terminate()
Expand Down Expand Up @@ -124,23 +125,23 @@ def clipboard_store(string):
os.close(fd_out)
os.remove(temp_out)
ret_text = ret_text.decode()
if ret_text:
if ret_text: # pragma: no cover
logger.error('Failed to store string in clipboard')
logger.error(ret_text)
raise
if ret_code:
if ret_code: # pragma: no cover
logger.error('Failed to store string in clipboard')
logger.error('xclip returned %d' % ret_code)
raise


def clipboard_retrieve():
p = subprocess.Popen(['xclip', '-o', '-selection', 'clipboard'], stdout=subprocess.PIPE)
output = ''
for line in p.stdout:
output += line.decode()
logger.debug('Clipboard retrieve "'+output+'"')
return output
# def clipboard_retrieve():
# p = subprocess.Popen(['xclip', '-o', '-selection', 'clipboard'], stdout=subprocess.PIPE)
# output = ''
# for line in p.stdout:
# output += line.decode()
# logger.debug('Clipboard retrieve "'+output+'"')
# return output


def wait_focused(id, timeout=10):
Expand Down
6 changes: 3 additions & 3 deletions src/eeschema_do
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ from kicad_auto.ui_automation import (
xdotool,
wait_for_window,
recorded_xvfb,
clipboard_store,
clipboard_retrieve
clipboard_store
)

# Return error codes
Expand Down Expand Up @@ -360,8 +359,9 @@ if __name__ == '__main__':
with recorded_xvfb(output_dir if args.record else None, args.command+'_eeschema_screencast.ogv',
width=args.rec_width, height=args.rec_height, colordepth=24):
with PopenContext(['eeschema', args.schematic], close_fds=True,
stderr=open(os.devnull, 'wb'), stdout=open(os.devnull, 'wb')) as eeschema_proc:
stderr=subprocess.DEVNULL, stdout=subprocess.DEVNULL) as eeschema_proc:
eeschema_skip_errors()
logger.debug('stdout: '+str(eeschema_proc.stdout)+' bool: '+str(bool(eeschema_proc.stdout)))
if args.command == 'export':
# Export
output_file = output_file_no_ext+'.'+args.file_format.lower()
Expand Down
3 changes: 2 additions & 1 deletion tests/eeschema/test_erc.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@
def test_erc_ok():
prj = 'good-project'
ctx = context.TestContextSCH('ERC_Ok', prj)
cmd = [PROG, 'run_erc']
cmd = [PROG, '-vv', '--record', 'run_erc']
ctx.run(cmd)
ctx.expect_out_file(prj+'.erc')
ctx.expect_out_file('run_erc_eeschema_screencast.ogv')
ctx.clean_up()


Expand Down

0 comments on commit 2d76118

Please sign in to comment.