Esempio n. 1
0
 def testThis(self):
     p = Path(__file__)
     self.assertTrue(p.isfile())
     self.assertFalse(p.isdir())
     c = Path.cwd()
     self.assertNotEqual(p, c)
     self.assertTrue(c.isdir())
Esempio n. 2
0
 def testThis(self):
     p = Path(__file__)
     self.assertTrue(p.isfile())
     self.assertFalse(p.isdir())
     c = Path.cwd()
     self.assertNotEqual(p, c)
     self.assertTrue(c.isdir())
Esempio n. 3
0
def runtests(cov=None, **params):
    import pulsar
    from pulsar.utils.path import Path
    from pulsar.apps.test import TestSuite
    from pulsar.apps.test.plugins import bench, profile
    import pulsar.utils.settings.backend
    #
    path = Path(__file__)
    path.add2python('stdnet', 1, down=['python-stdnet'], must_exist=False)
    strip_dirs = [Path(pulsar.__file__).parent.parent, os.getcwd()]
    #
    suite = TestSuite(description='Pulsar Asynchronous test suite',
                      modules=('tests',
                               ('examples', 'tests'),
                               ('examples', 'test_*')),
                      plugins=(bench.BenchMark(),
                               profile.Profile()),
                      pidfile='test.pid',
                      **params).start()
    #
    if suite.cfg.coveralls:
        from pulsar.utils.cov import coveralls
        coveralls(strip_dirs=strip_dirs,
                  stream=suite.stream,
                  repo_token='CNw6W9flYDDXZYeStmR1FX9F4vo0MKnyX')
Esempio n. 4
0
def runtests(**params):
    import pulsar
    from pulsar.utils.path import Path
    from pulsar.apps.test import TestSuite
    from pulsar.apps.test.plugins import bench, profile
    import pulsar.utils.settings.backend
    #
    path = Path(__file__)
    path.add2python('stdnet', 1, down=['python-stdnet'], must_exist=False)
    #
    TestSuite(description='Pulsar Asynchronous test suite',
              modules=('tests',
                       ('examples', 'tests'),
                       ('examples', 'test_*')),
              plugins=(bench.BenchMark(),
                       profile.Profile()),
              pidfile='test.pid',
              **params).start()
Esempio n. 5
0
 def test_send_images(self):
     path = Path(examples.__file__).parent.parent
     path = path.join("docs", "source", "_static")
     files = []
     sent = []
     for name in ("pulsar.png", "favicon.ico"):
         with open(path.join(name), "rb") as file:
             image = file.read()
         sent.append(image)
         files.append(("images", (name, image)))
     client = self._client
     response = yield from client.post(self.httpbin("post"), files=files)
     self.assertEqual(response.status_code, 200)
     ct = response.request.headers["content-type"]
     self.assertTrue(ct.startswith("multipart/form-data; boundary="))
     data = response.json()
     images = data["files"]["images"]
     self.assertEqual(len(images), 2)
     for image, s in zip(images, sent):
         image = b64decode(image.encode("utf-8"))
         self.assertEqual(image, s)
Esempio n. 6
0
 def test_send_images(self):
     path = Path(examples.__file__).parent.parent
     path = path.join('docs', 'source', '_static')
     files = []
     sent = []
     for name in ('pulsar.png', 'favicon.ico'):
         with open(path.join(name), 'rb') as file:
             image = file.read()
         sent.append(image)
         files.append(('images', (name, image)))
     client = self._client
     response = yield from client.post(self.httpbin('post'), files=files)
     self.assertEqual(response.status_code, 200)
     ct = response.request.headers['content-type']
     self.assertTrue(ct.startswith('multipart/form-data; boundary='))
     data = response.json()
     images = data['files']['images']
     self.assertEqual(len(images), 2)
     for image, s in zip(images, sent):
         image = b64decode(image.encode('utf-8'))
         self.assertEqual(image, s)
Esempio n. 7
0
 def test_send_images(self):
     path = Path(examples.__file__).parent.parent
     path = path.join('docs', 'source', '_static')
     files = []
     sent = []
     for name in ('pulsar.png', 'favicon.ico'):
         with open(path.join(name), 'rb') as file:
             image = file.read()
         sent.append(image)
         files.append(('images', (name, image)))
     client = self._client
     response = yield from client.post(self.httpbin('post'), files=files)
     self.assertEqual(response.status_code, 200)
     ct = response.request.headers['content-type']
     self.assertTrue(ct.startswith('multipart/form-data; boundary='))
     data = response.json()
     images = data['files']['images']
     self.assertEqual(len(images), 2)
     for image, s in zip(images, sent):
         image = b64decode(image.encode('utf-8'))
         self.assertEqual(image, s)
Esempio n. 8
0
 def __init__(self, file, version, config=None):
     file = Path(file)
     if file.isdir():
         appdir = file
     elif file.isfile():
         appdir = file.realpath().parent
     else:
         raise ValueError('Could not find %s' % file)
     self.file = file
     self.path = appdir.realpath()
     self.version = version or __version__
     if self.has_module:
         _, name = self.path.split()
     else:
         # otherwise it is the name of the file
         _, name = self.file.split()
     self.name = name
     self.config = cfg = {}
     if config:
         for setting in config:
             setting = copy(setting)
             setting.extension = self.name
             cfg[setting.name] = setting
Esempio n. 9
0
def runtests(cov=None, **params):
    import pulsar
    from pulsar.utils.path import Path
    from pulsar.apps.test import TestSuite
    from pulsar.apps.test.plugins import bench, profile
    import pulsar.utils.settings.backend
    #
    path = Path(__file__)
    path.add2python('stdnet', 1, down=['python-stdnet'], must_exist=False)
    strip_dirs = [Path(pulsar.__file__).parent.parent, os.getcwd()]
    #
    suite = TestSuite(description='Pulsar Asynchronous test suite',
                      modules=('tests', ('examples', 'tests'), ('examples',
                                                                'test_*')),
                      plugins=(bench.BenchMark(), profile.Profile()),
                      pidfile='test.pid',
                      **params).start()
    #
    if suite.cfg.coveralls:
        from pulsar.utils.cov import coveralls
        coveralls(strip_dirs=strip_dirs,
                  stream=suite.stream,
                  repo_token='CNw6W9flYDDXZYeStmR1FX9F4vo0MKnyX')
Esempio n. 10
0
 def __init__(self, file, version, config=None):
     file = Path(file)
     if file.isdir():
         appdir = file
     elif file.isfile():
         appdir = file.realpath().parent
     else:
         raise ValueError('Could not find %s' % file)
     self.file = file
     self.path = appdir.realpath()
     self.version = version or __version__
     if self.has_module:
         _, name = self.path.split()
     else:
         # otherwise it is the name of the file
         _, name = self.file.split()
     self.name = name
     self.config = cfg = {}
     if config:
         for setting in config:
             setting = copy(setting)
             setting.extension = self.name
             cfg[setting.name] = setting
Esempio n. 11
0
def run(**params):
    args = params.get('argv', sys.argv)
    if '--coveralls' in args:
        import pulsar
        from pulsar.utils.path import Path
        from pulsar.apps.test.cov import coveralls

        path = Path(__file__)
        repo_token = None
        strip_dirs = [Path(pulsar.__file__).parent.parent, os.getcwd()]
        if os.path.isfile('.coveralls-repo-token'):
            with open('.coveralls-repo-token') as f:
                repo_token = f.read().strip()
        code = coveralls(strip_dirs=strip_dirs, repo_token=repo_token)
        sys.exit(0)
    # Run the test suite
    if '--coverage' in args or params.get('coverage'):
        import coverage
        print('Start coverage')
        p = current_process()
        p._coverage = coverage.coverage(data_suffix=True)
        p._coverage.start()
    runtests(**params)
Esempio n. 12
0
def runtests():
    from pulsar.apps.test import TestSuite
    from pulsar.apps.test.plugins import bench, profile

    args = sys.argv
    if '--coveralls' in args:
        import lux
        import pulsar
        from pulsar.utils.path import Path
        from pulsar.apps.test.cov import coveralls

        path = Path(__file__)
        repo_token = None
        strip_dirs = [Path(lux.__file__).parent.parent, os.getcwd()]
        if os.path.isfile('.coveralls-repo-token'):
            with open('.coveralls-repo-token') as f:
                repo_token = f.read().strip()
        code = coveralls(strip_dirs=strip_dirs, repo_token=repo_token)
        sys.exit(0)
    #
    TestSuite(description='Lux Asynchronous test suite',
              modules=['tests'],
              plugins=(bench.BenchMark(), profile.Profile())).start()
Esempio n. 13
0
def runtests(**params):
    import stdnet
    from stdnet.utils import test
    #
    strip_dirs = [Path(stdnet.__file__).parent.parent, os.getcwd()]
    #
    suite = TestSuite(description='Stdnet Asynchronous test suite',
                      modules=('tests.all', ),
                      plugins=(test.StdnetPlugin(), bench.BenchMark(),
                               profile.Profile()),
                      **params)
    suite.bind_event('tests', test.create_tests)
    suite.start()
    #
    if suite.cfg.coveralls:
        from pulsar.utils.cov import coveralls
        coveralls(strip_dirs=strip_dirs,
                  stream=suite.stream,
                  repo_token='ZQinNe5XNbzQ44xYGTljP8R89jrQ5xTKB')
Esempio n. 14
0
def run():
    from pulsar.apps.test import TestSuite
    from pulsar.apps.test.plugins import bench, profile

    args = sys.argv
    if '--coveralls' in args:
        import cloud
        from pulsar.utils.path import Path
        from pulsar.apps.test.cov import coveralls

        repo_token = None
        strip_dirs = [Path(cloud.__file__).parent.parent, os.getcwd()]
        if os.path.isfile('.coveralls-repo-token'):
            with open('.coveralls-repo-token') as f:
                repo_token = f.read().strip()
        coveralls(strip_dirs=strip_dirs, repo_token=repo_token)
        sys.exit(0)
    # Run the test suite
    #
    TestSuite(description='pulsar-pusher asynchronous test suite',
              modules=['tests'],
              plugins=(bench.BenchMark(), profile.Profile()),
              test_timeout=30,
              config='config.py').start()
Esempio n. 15
0
 def testAdd2Python_failure(self):
     p = Path()
     self.assertRaises(ImportError, p.add2python, 'kaputttt')
     self.assertFalse(p.add2python('vdfvdavfdv', must_exist=False))
Esempio n. 16
0
 def testAdd2Python(self):
     p = Path("/sdjc/scdskjcdnsd/dhjdhjdjksdjksdksd")
     module = p.add2python("pulsar")
     self.assertEqual(module.__name__, "pulsar")
     self.assertRaises(ValueError, p.add2python, "kaputttt")
Esempio n. 17
0
 def testDir(self):
     c = Path.cwd()
     self.assertEqual(c, c.dir())
     c = Path('/sdjc/scdskjcdnsd/dhjdhjdjksdjksdksd')
     self.assertFalse(c.exists())
     self.assertRaises(ValueError, c.dir)
Esempio n. 18
0
 def testAdd2Python(self):
     p = Path('/sdjc/scdskjcdnsd/dhjdhjdjksdjksdksd')
     module = p.add2python('pulsar')
     self.assertEqual(module.__name__, 'pulsar')
     self.assertRaises(ValueError, p.add2python, 'kaputttt')
Esempio n. 19
0
import sys
import os
try:
    from pulsar.utils.path import Path
except ImportError:
    # pulsar not available, we are in dev
    path = os.path.join(os.path.dirname(os.getcwd()), 'pulsar')
    if os.path.isdir(path):
        sys.path.append(path)
    from pulsar.utils.path import Path

import lux
path = Path(__file__)
path.add2python('stdnet', up=1, down=['python-stdnet'])
Esempio n. 20
0
 def testDir(self):
     c = Path.cwd()
     self.assertEqual(c, c.dir())
     c = Path('/sdjc/scdskjcdnsd/dhjdhjdjksdjksdksd')
     self.assertFalse(c.exists())
     self.assertRaises(ValueError, c.dir)
Esempio n. 21
0
'''Tests django chat application.'''
import json

from pulsar import send, get_application, Queue
from pulsar.utils.path import Path
from pulsar.apps import http, ws
from pulsar.apps.test import unittest, dont_run_with_thread

try:
    manage = Path(__file__).add2python('manage', up=1)
except ImportError:
    manage = None


def start_server(actor, name, argv):
    # we need to make sure djangoapp is in the python path
    actor.params.django_pulsar_name = name
    manage.execute_from_command_line(argv)
    app = yield get_application(name)
    yield app.event('start')


class MessageHandler(ws.WS):

    def __init__(self):
        self.queue = Queue()

    def get(self):
        return self.queue.get()

    def on_message(self, websocket, message):
Esempio n. 22
0
import os
import sys
import json
import time
try:
    import pulsar
except ImportError:  # pragma nocover
    sys.path.append('../../')
    import pulsar
from pulsar.utils.path import Path
from pulsar.apps import ws, wsgi, rpc, pubsub

CHAT_DIR = os.path.dirname(__file__)

stdnet = Path(__file__).add2python('stdnet',
                                   3,
                                   down=['python-stdnet'],
                                   must_exist=False)
if stdnet:
    # Add option to use redis pubsub instead of local pubsub
    # If we are testsing don't do anything, the setting is already available
    import pulsar.utils.settings.backend


class PubSubClient(pubsub.Client):
    def __init__(self, connection):
        self.connection = connection

    def __call__(self, channel, message):
        if channel == 'webchat':
            self.connection.write(message)
Esempio n. 23
0
 def testAdd2Python(self):
     p = Path('/sdjc/scdskjcdnsd/dhjdhjdjksdjksdksd')
     module = p.add2python('pulsar')
     self.assertEqual(module.__name__, 'pulsar')
     self.assertRaises(ValueError, p.add2python, 'kaputttt')
Esempio n. 24
0
 def testAdd2Python_failure(self):
     p = Path()
     self.assertRaises(ImportError, p.add2python, 'kaputttt')
     self.assertFalse(p.add2python('vdfvdavfdv', must_exist=False))
Esempio n. 25
0
   :member-order: bysource

.. autoclass:: server
   :members:
   :member-order: bysource
'''
try:
    import pulsar
except ImportError:
    import sys
    sys.path.append('../../')
    import pulsar
from pulsar.utils.path import Path
from pulsar.apps import rpc, tasks, wsgi

Path(pulsar.__file__).add2python('stdnet', up=2, down=['python-stdnet'],
                                 must_exist=False)

TASK_PATHS = ['sampletasks.*']


class RpcRoot(rpc.PulsarServerCommands, tasks.TaskQueueRpcMixin):
    '''The :class:`pulsar.apps.rpc.JSONRPC` handler which communicates
with the task queue.'''

    def rpc_runpycode(self, request, code=None, **params):
        return self.task_run(request, 'runpycode', code=code, **params)


class Rpc(wsgi.LazyWsgi):

    def __init__(self, tqname):