Permalink
Browse files

Made tests pass. Added a coverage fab task.

  • Loading branch information...
1 parent 77c6903 commit 7e088ec89464b388252d13da4c5e9f45cd2dd3e9 @elachuni elachuni committed Feb 25, 2012
Showing with 26 additions and 1 deletion.
  1. +3 −1 .gitignore
  2. +8 −0 fabfile.py
  3. +2 −0 requirements.txt
  4. +13 −0 spacecraft/tests/test_server.py
View
@@ -2,4 +2,6 @@
dropin.cache
_trial_temp
twistd.pid
-virtualenv/
+virtualenv/
+.coverage
+htmlcov/
View
@@ -33,6 +33,14 @@ def test():
check_bootstrap()
local('./virtualenv/bin/trial spacecraft')
+def coverage():
+ cov = lambda args: local("virtualenv/bin/coverage " + args,
+ capture=False)
+ local("rm -rf .coverage coverage/")
+ cov("run ./virtualenv/bin/trial spacecraft")
+ cov("combine")
+ cov("html -d htmlcov/ --include='spacecraft/*'")
+
# -----------------------------------------------------------------
# Tasks from here down aren't intended to be used directly
View
@@ -1,2 +1,4 @@
svn+http://pybox2d.googlecode.com/svn/trunk/
twisted==10.1.0
+coverage
+mock
@@ -1,4 +1,5 @@
# -*- coding: utf-8 *-*
+from mock import Mock
from twisted.trial.unittest import TestCase
from twisted.internet.endpoints import TCP4ClientEndpoint
from twisted.internet.protocol import Factory, Protocol
@@ -60,15 +61,19 @@ class TestGame(TestCase):
def test_create_player(self):
map = world.Game(100, 100)
player = server.Player()
+ player.transport = Mock()
player.register(map)
+ reactor.iterate()
self.assertEquals(len(map.world.bodies), 1)
prepr = player.object.get_full_position()
self.assertTrue("position" in prepr)
def test_monitor(self):
map = world.Game(100, 100)
player = server.Player()
+ player.transport = Mock()
player.register(map)
+ reactor.iterate()
monitor = server.Monitor()
monitor.register(map)
result = []
@@ -80,14 +85,18 @@ def test_monitor(self):
def test_throttle(self):
map = world.Game(100, 100)
player = server.Player()
+ player.transport = Mock()
player.register(map)
+ reactor.iterate()
player.messageReceived(dict(type="throttle", value=0.5))
self.assertEquals(player.object.throttle, 0.5)
def test_gps(self):
map = world.Game(100, 100)
player = server.Player()
+ player.transport = Mock()
player.register(map)
+ reactor.iterate()
result = []
player.sendMessage = update_collector(result)
player.sendUpdate()
@@ -100,11 +109,15 @@ def test_gps(self):
def test_radar(self):
map = world.Game(100, 100)
player = server.Player()
+ player.transport = Mock()
player.register(map)
+ reactor.iterate()
player.object.body.position = (100, 100)
player2 = server.Player()
+ player2.transport = Mock()
player2.register(map)
+ reactor.iterate()
player2.object.body.position = (120, 100)
result = []

0 comments on commit 7e088ec

Please sign in to comment.