Permalink
Browse files

functional: add screen capture tests

  • Loading branch information...
1 parent db38c1e commit c4a710e64e2a65f6b646983115f401da5ad7e631 Marc Sibson committed Feb 16, 2011
Showing with 56 additions and 3 deletions.
  1. +1 −1 MANIFEST.in
  2. +55 −0 tests/functional/test_screen.py
  3. +0 −2 tests/functional/test_send_events.py
View
2 MANIFEST.in
@@ -2,4 +2,4 @@ include *.txt README.rst
include setup.py setup.cfg
include scripts/vncdotool
include vncdotool/*.py
-include tests/*.py
+recursive-include tests *.py *.png
View
55 tests/functional/test_screen.py
@@ -0,0 +1,55 @@
+import pexpect
+import sys
+import os.path
+
+DATADIR = os.path.join(os.path.dirname(__file__), 'data')
+
+
+class TestVNCCapture(object):
+
+ def tearDown(self):
+ self.server.terminate(force=True)
+
+ def run_server(self, server):
+ cmd = '%s -rfbport 5910 -rfbwait 1000' % server
+ self.server = pexpect.spawn(cmd, timeout=2)
+ self.server.logfile_read = sys.stdout
+
+ def run_vncdotool(self, commands, exitcode=0):
+ cmd = 'vncdotool -d 10 ' + commands
+ vnc = pexpect.spawn(cmd, logfile=sys.stdout, timeout=5)
+ vnc.logfile_read = sys.stdout
+ vnc.expect(pexpect.EOF)
+ if vnc.isalive():
+ vnc.wait()
+
+ assert vnc.exitstatus == exitcode, vnc.exitstatus
+
+ def assertFilesEqual(self, filename, othername):
+ content = open(filename, 'rb').read()
+ othercontent = open(othername, 'rb').read()
+
+ assert content == othercontent
+
+ def testCaptureExample(self):
+ fname = 'test_capture_example.png'
+ self.run_server('example')
+ self.run_vncdotool('capture %s' % fname)
+ self.assertFilesEqual(fname, os.path.join(DATADIR, 'example.png'))
+
+ def testExpectExampleExactly(self):
+ self.run_server('example')
+ self.run_vncdotool('expect %s 0' % os.path.join(DATADIR, 'example.png'))
+
+ def testExpectExampleSloppy(self):
+ self.run_server('example')
+ example = os.path.join(DATADIR, 'example.png')
+ self.run_vncdotool('move 30 20 expect %s 20' % example)
+
+ def testExpectFailsExample(self):
+ self.run_server('example')
+ simple = os.path.join(DATADIR, 'simple.png')
+ try:
+ self.run_vncdotool('expect %s 0' % simple, exitcode=10)
+ except pexpect.TIMEOUT:
+ pas:), exitcode=10)), exitcode=10)
View
2 tests/functional/test_send_events.py
@@ -1,5 +1,3 @@
-# Copyright 07-Feb-2011 Evertz Microsystems Ltd. All rights reserved.
-
import pexpect
import unittest
import sys

0 comments on commit c4a710e

Please sign in to comment.