This repository has been archived by the owner on Aug 7, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
21 changed files
with
862 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,83 @@ | ||
from __future__ import absolute_import | ||
|
||
from unittest import TestCase | ||
from unittest import TestCase, skip | ||
|
||
from simulation.game_state import GameState | ||
from simulation.location import Location | ||
from simulation.turn_manager import state_provider | ||
from simulation.world_map import WorldMap | ||
from simulation.world_state import WorldState | ||
from simulation.avatar.avatar_manager import AvatarManager | ||
|
||
import service | ||
|
||
from .test_simulation.dummy_avatar import MoveEastDummy | ||
from .test_simulation.maps import MockPickup | ||
from .test_simulation.test_world_map import MockCell | ||
|
||
class SimpleAvatarManager(object): | ||
avatars = [MoveEastDummy(1, Location(0, -1))] | ||
class SimpleAvatarManager(AvatarManager): | ||
def __init__(self): | ||
super(SimpleAvatarManager, self).__init__() | ||
|
||
# TODO: Write test for the new API... | ||
class TestService(TestCase): | ||
def test_healthy(self): | ||
avatar = MoveEastDummy(1, Location(0, -1)) | ||
self.avatars_to_create_by_id = { | ||
1 : avatar | ||
} | ||
|
||
class TestServiceAPI(TestCase): | ||
def setUp(self): | ||
service.app.config['TESTING'] = True | ||
self.app = service.app.test_client() | ||
|
||
def test_healthy(self): | ||
response = self.app.get('/') | ||
self.assertEqual(response.data, 'HEALTHY') | ||
|
||
class TestServiceInternals(TestCase): | ||
def setUp(self): | ||
self.user_id = 1 | ||
|
||
def setup_world(self): | ||
avatar_manager = SimpleAvatarManager() | ||
CELLS = [ | ||
[ | ||
{'pickup': MockPickup('b'), 'avatar': avatar_manager.avatars_to_create_by_id}, | ||
{}, | ||
{'generates_score': True}, | ||
], | ||
[ | ||
{}, | ||
{'habitable': False}, | ||
{'pickup': MockPickup('a')}, | ||
], | ||
] | ||
grid = {Location(x, y-1): MockCell(Location(x, y-1), **CELLS[x][y]) | ||
for y in xrange(3) for x in xrange(2)} | ||
state_provider.set_world(GameState(WorldMap(grid, {}), avatar_manager)) | ||
|
||
world_state = WorldState(state_provider) | ||
world_state.ready_to_update = True | ||
|
||
return world_state.get_updates() | ||
|
||
def test_player_dict(self): | ||
player_list = self.setup_world()['players']['create'] | ||
self.assertEqual(len(player_list), 1) | ||
details = player_list[0] | ||
self.assertEqual(details['id'], 1) | ||
self.assertEqual(details['x'], 0) | ||
self.assertEqual(details['y'], -1) | ||
self.assertEqual(details['health'], 5) | ||
self.assertEqual(details['score'], 0) | ||
|
||
def test_score_locations(self): | ||
result = self.setup_world()['map_features']['score_point']['create'] | ||
self.assertEqual(result[0]['x'], 0) | ||
self.assertEqual(result[0]['y'], 1) | ||
|
||
@skip("not implemented") | ||
def test_pickup_list(self): | ||
result = self.setup_world()['map_features']['pickup']['create'] | ||
pickup_pos_list = [(pickup['x'], pickup['y']) for pickup in result] | ||
self.assertIn((1, 1), pickup_pos_list) | ||
self.assertIn((0, -1), pickup_pos_list) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
from setuptools import find_packages, setup | ||
import unittest | ||
import os | ||
|
||
def custom_test_suite(): | ||
return unittest.TestLoader().discover('tests', pattern='test_*.py') | ||
|
||
setup( | ||
name='integration-tests', | ||
include_package_data=True, | ||
install_requires=[ | ||
], | ||
tests_require=[ | ||
'httmock', | ||
'psutil' | ||
], | ||
test_suite="setup.custom_test_suite", | ||
zip_safe=False, | ||
) |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import signal | ||
import requests | ||
|
||
import os | ||
import subprocess | ||
import sys | ||
|
||
import traceback | ||
import logging | ||
import psutil | ||
import time | ||
import sys | ||
import socket | ||
|
||
FNULL = open(os.devnull, 'w') | ||
|
||
logging.basicConfig() | ||
LOGGER = logging.getLogger(__name__) | ||
LOGGER.setLevel(logging.DEBUG) | ||
|
||
def get_ip(): | ||
# http://stackoverflow.com/a/28950776/671626 | ||
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) | ||
try: | ||
# doesn't even have to be reachable | ||
s.connect(('10.255.255.255', 0)) | ||
IP = s.getsockname()[0] | ||
except: | ||
IP = '127.0.0.1' | ||
finally: | ||
s.close() | ||
return IP | ||
|
||
def run_command_async(args, cwd=".", verbose=False): | ||
if verbose: | ||
p = subprocess.Popen(args, cwd=cwd) | ||
else: | ||
p = subprocess.Popen(args, cwd=cwd, stdout=FNULL, stderr=subprocess.STDOUT) | ||
return p | ||
|
||
def process_tree(pid): | ||
parent = psutil.Process(pid) | ||
to_kill = [pid] | ||
for child in parent.children(recursive=True): | ||
to_kill = to_kill + process_tree(child.pid) | ||
return to_kill | ||
|
||
def kill_process_tree(pid): | ||
try: | ||
LOGGER.info("Current process %s" % str(os.getpid())) | ||
LOGGER.info("Process tree...") | ||
to_kill = process_tree(pid) | ||
LOGGER.info("Killing processes... %s" % str(to_kill)) | ||
for pid in to_kill: | ||
os.kill(pid, signal.SIGKILL) | ||
LOGGER.info("Waiting for processes to terminate...") | ||
for pid in to_kill: | ||
os.system("wait " + str(pid)) | ||
LOGGER.info("Process tree killed successfully...") | ||
except Exception as e: | ||
LOGGER.warn("An exception occured while killing the process tree...") | ||
logging.error(traceback.format_exc()) |
Oops, something went wrong.