Created
May 4, 2010 16:18
-
-
Save josip/389607 to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
import os, shutil, sys | |
from setuptools import find_packages, setup | |
from setuptools.command import sdist | |
from setuptools import Command | |
ROOT_PATH = os.path.dirname(os.path.abspath(__file__)) | |
# The idea is to create a clean environment for testing, | |
# therefore, first we create and start test-introducer and test-node. | |
# Application's code is copied over to test-node/public_html and Windmill is started | |
# To cleanup after the test session ends (Control+C/D) we need to | |
# stop test-introducer and test-node, to do that we're using a fake Windmill Controller (as I couldn't find anything better). | |
# Windmill uses these Controllers to manage browser processes, but since the "API" is really simple, | |
# we are able to setup a fake one, in order to stop started Tahoe nodes. | |
class Test(Command): | |
description = "run tests with Windmill. " | |
user_options = [ | |
("browser=", "b", "browser to run the tests in. defaults to firefox."), | |
("quit-immediately", "u", "quit browser immediately after tests are completed.") | |
] | |
port = "6543" | |
introducer_path = os.path.join(ROOT_PATH, "test-introducer") | |
introducer_furl = None | |
node_path = os.path.join(ROOT_PATH, "test-node") | |
def initialize_options(self): | |
self.browser = "firefox" | |
self.quit_immediately = False | |
def finalize_options(self): | |
self.browser = self.browser.upper() | |
def run(self): | |
self.start_server() | |
shutil.copytree(os.path.join(ROOT_PATH, "app"), os.path.join(ROOT_PATH, "test-node", "public_html", "musicplayer")) | |
import windmill | |
from windmill.bin import admin_lib | |
windmill.stdout, windmill.stdin = sys.stdout, sys.stdin | |
admin_lib.configure_global_settings(logging_on=self.verbose) | |
windmill.settings["TEST_URL"] = "http://127.0.0.1:%s/static/musicplayer" % self.port | |
windmill.settings["START_" + self.browser] = True | |
windmill.settings["JAVASCRIPT_TEST_DIR"] = os.path.join(ROOT_PATH, "tests") | |
windmill.settings['EXIT_ON_DONE'] = self.quit_immediately | |
windmill.teardown_directories.append(self.introducer_path) | |
windmill.teardown_directories.append(self.node_path) | |
shell_objects = admin_lib.setup() | |
windmill.settings['controllers'].append(FakeWindmillController(self.node_path, self.introducer_path)) | |
admin_lib.runserver_action(shell_objects) | |
def start_server(self): | |
from allmydata.scripts.create_node import create_introducer, create_node | |
from allmydata.scripts.startstop_node import do_start | |
from time import sleep | |
start_opts = {"syslog": None, "profile": None} | |
create_introducer(self.introducer_path, {"nickname": "musicplayer-test-introducer"}, out=None) | |
do_start(self.introducer_path, start_opts, out=None) | |
furl_path = os.path.join(self.introducer_path, "introducer.furl") | |
while not os.path.isfile(furl_path): | |
sleep(1) | |
furl_file = open(furl_path, "r") | |
self.introducer_furl = furl_file.read().rstrip() | |
furl_file.close() | |
create_node(self.node_path, {"introducer": self.introducer_furl, "nickname": "musicplayer-test-node", "webport": self.port}) | |
do_start(self.node_path, start_opts, out=None) | |
class FakeWindmillController(object): | |
def __init__(self, *nodes): | |
self.nodes = nodes | |
def start(self): | |
pass | |
def stop(self): | |
from allmydata.scripts.startstop_node import do_stop | |
[do_stop(node, None) for node in self.nodes] | |
def kill(self, kill_signal=None): | |
pass | |
setup( | |
name = "tahoe-music-player", | |
cmdclass = { | |
"test": Test | |
} | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment