Ejemplo n.º 1
0
 def __enter__(self):
     self.proc = Popen([sys.executable, '-u', '-m', 'tests.mockserver', '-t', 'dns'],
                       stdout=PIPE, env=get_testenv())
     host, port = self.proc.stdout.readline().strip().decode('ascii').split(":")
     self.host = host
     self.port = int(port)
     return self
Ejemplo n.º 2
0
 def __enter__(self):
     from scrapy.utils.test import get_testenv
     pargs = [sys.executable, '-u', '-m', 'scrapy.utils.benchserver']
     self.proc = subprocess.Popen(pargs,
                                  stdout=subprocess.PIPE,
                                  env=get_testenv())
     self.proc.stdout.readline()
Ejemplo n.º 3
0
 def __enter__(self):
     from scrapy.utils.test import get_testenv
     self.proc = Popen(
         [sys.executable, '-u', '-m', 'scrapy.tests.mockserver'],
         stdout=PIPE,
         env=get_testenv())
     self.proc.stdout.readline()
Ejemplo n.º 4
0
    def setUp(self):
        self.temp_path = mkdtemp()
        self.cwd = self.temp_path
        self.proj_path = join(self.temp_path, self.project_name)
        self.proj_mod_path = join(self.proj_path, self.project_name)
        self.env = get_testenv()

        self.call('startproject', self.project_name)
        self.cwd = join(self.temp_path, self.project_name)
        os.chdir(self.cwd)
        self.env['SCRAPY_SETTINGS_MODULE'] = '%s.settings' % self.project_name
        self.external_path = join(self.cwd, 'external.json')
        with open(self.external_path, 'w') as external:
            external.write('''
[
  {
    "name": "PythonSpider",
    "command": "spiders/sample1.py"
  },

  {
    "name": "JavaSpider",
    "command": "java",
    "args": ["MyClass"]
  }
]
''')
Ejemplo n.º 5
0
    def start(self):
        from scrapy.utils.test import get_testenv
        script = """
import sys
from mitmproxy.tools.main import mitmdump
sys.argv[0] = "mitmdump"
sys.exit(mitmdump())
        """
        cert_path = os.path.join(os.path.abspath(os.path.dirname(__file__)),
                                 'keys', 'mitmproxy-ca.pem')
        self.proc = Popen([
            sys.executable,
            '-c',
            script,
            '--listen-host',
            '127.0.0.1',
            '--listen-port',
            '0',
            '--proxyauth',
            '%s:%s' % (self.auth_user, self.auth_pass),
            '--certs',
            cert_path,
            '--ssl-insecure',
        ],
                          stdout=PIPE,
                          env=get_testenv())
        line = self.proc.stdout.readline().decode('utf-8')
        host_port = re.search(r'listening at http://([^:]+:\d+)',
                              line).group(1)
        address = 'http://%s:%s@%s' % (self.auth_user, self.auth_pass,
                                       host_port)
        return address
Ejemplo n.º 6
0
 def run_script(self, script_name):
     script_path = os.path.join(self.script_dir, script_name)
     args = (sys.executable, script_path)
     p = subprocess.Popen(args, env=get_testenv(),
                          stdout=subprocess.PIPE, stderr=subprocess.PIPE)
     stdout, stderr = p.communicate()
     return stderr.decode('utf-8')
Ejemplo n.º 7
0
 def __enter__(self):
     self.path = Path(mkdtemp())
     self.proc = Popen([sys.executable, '-u', '-m', 'tests.ftpserver', '-d', str(self.path)],
                       stderr=PIPE, env=get_testenv())
     for line in self.proc.stderr:
         if b'starting FTP server' in line:
             break
     return self
Ejemplo n.º 8
0
    def __enter__(self):
        self.proc = Popen([sys.executable, '-u', '-m', 'tests.mockserver', '-t', 'http'],
                          stdout=PIPE, env=get_testenv())
        http_address = self.proc.stdout.readline().strip().decode('ascii')
        https_address = self.proc.stdout.readline().strip().decode('ascii')

        self.http_address = http_address
        self.https_address = https_address

        return self
Ejemplo n.º 9
0
    def __enter__(self):
        from scrapy.utils.test import get_testenv

        self.proc = Popen([sys.executable, '-u', '-m', 'tests.mockserver'],
                          stdout=PIPE, env=get_testenv())
        http_address = self.proc.stdout.readline().strip().decode('ascii')
        https_address = self.proc.stdout.readline().strip().decode('ascii')

        self.http_address = http_address
        self.https_address = https_address

        return self
Ejemplo n.º 10
0
 def setUp(self):
     self.temp_path = mkdtemp()
     self.cwd = self.temp_path
     self.proj_path = join(self.temp_path, self.project_name)
     self.proj_mod_path = join(self.proj_path, self.project_name)
     self.env = get_testenv()
Ejemplo n.º 11
0
 def setUp(self):
     self.env = get_testenv()
     self.env["SCRAPY_SETTINGS_MODULE"] = "tests.test_cmdline.settings"
Ejemplo n.º 12
0
 def setUp(self):
     self.proc = Popen([sys.executable, "-u", "-m", "scrapy.tests.mockserver"], stdout=PIPE, env=get_testenv())
     self.proc.stdout.readline()
Ejemplo n.º 13
0
 def setUp(self):
     self.env = get_testenv()
     self.env['SCRAPY_SETTINGS_MODULE'] = 'tests.test_cmdline.settings'
Ejemplo n.º 14
0
 def setUp(self):
     self.temp_path = mkdtemp()
     self.cwd = self.temp_path
     self.proj_path = join(self.temp_path, self.project_name)
     self.proj_mod_path = join(self.proj_path, self.project_name)
     self.env = get_testenv()
Ejemplo n.º 15
0
 def __enter__(self):
     from scrapy.utils.test import get_testenv
     self.proc = Popen([sys.executable, '-u', '-m', 'scrapy.tests.mockserver'],
                       stdout=PIPE, env=get_testenv())
     self.proc.stdout.readline()
Ejemplo n.º 16
0
 def __enter__(self):
     from scrapy.utils.test import get_testenv
     pargs = [sys.executable, '-u', '-m', 'scrapy.utils.benchserver']
     self.proc = subprocess.Popen(pargs, stdout=subprocess.PIPE,
                                  env=get_testenv())
     self.proc.stdout.readline()
Ejemplo n.º 17
0
 def setUp(self):
     self.env = get_testenv()
     self.env['SCRAPY_SETTINGS_MODULE'] = 'tests.test_cmdline.settings'
Ejemplo n.º 18
0
 def setUp(self):
     self.env = get_testenv()
     self.env["SCRAPY_SETTINGS_MODULE"] = "tests.test_cmdline.settings"
Ejemplo n.º 19
0
        def __enter__(self):
        from scrapy.utils.test import get_testenv
        pargs = [sys.executable, '-u', '-m', 'scrapy.utils.benchserver']
        self.proc = subprocess.Popen(pargs, stdout=subprocess.PIPE,
                                     env=get_testenv())
        self.proc.stdout.readline()
    
            # Set the request method through curl's irritating interface which makes
        # up names for almost every single method
        curl_options = {
            'GET': pycurl.HTTPGET,
            'POST': pycurl.POST,
            'PUT': pycurl.UPLOAD,
            'HEAD': pycurl.NOBODY,
        }
        custom_methods = set(['DELETE', 'OPTIONS', 'PATCH'])
        for o in curl_options.values():
            curl.setopt(o, False)
        if request.method in curl_options:
            curl.unsetopt(pycurl.CUSTOMREQUEST)
            curl.setopt(curl_options[request.method], True)
        elif request.allow_nonstandard_methods or request.method in custom_methods:
            curl.setopt(pycurl.CUSTOMREQUEST, request.method)
        else:
            raise KeyError('unknown method ' + request.method)
    
        def __str__(self):
        return self.message
    
        _TIMEDELTA_PATTERN = re.compile(
        r'\s*(%s)\s*(\w*)\s*' % _FLOAT_PATTERN, re.IGNORECASE)
    
        @gen_test
    def asyncSetUp(self):
        listener, port = bind_unused_port()
        event = Event()
    
    from tornado.escape import json_decode
from tornado.test.httpserver_test import TypeCheckHandler
from tornado.test.util import ignore_deprecation
from tornado.testing import AsyncHTTPTestCase
from tornado.web import RequestHandler, Application
from tornado.wsgi import WSGIApplication, WSGIContainer, WSGIAdapter
    
    
def future_set_result_unless_cancelled(future, value):
    '''Set the given ``value`` as the `Future`'s result, if not cancelled.
    
        @gen_test
    def test_swallow_context_exception(self):
        with ignore_deprecation():
            # Test exception handling: exceptions thrown into the stack context
            # can be caught and ignored.
            @gen.coroutine
            def f2():
                (yield gen.Callback(1))()
                yield gen.Wait(1)
                self.io_loop.add_callback(lambda: 1 / 0)
                try:
                    yield gen.Task(self.io_loop.add_timeout,
                                   self.io_loop.time() + 10)
                except ZeroDivisionError:
                    raise gen.Return(42)
    
    
class Suspect(OutOfService):
    
        def setUp(cls):
        ''' Function/test case scope setup. '''
        cls.output = StringIO()
        cls.saved_stdout = sys.stdout
        sys.stdout = cls.output
    
        def test_dog_greek_localization(self):
        self.assertEqual(self.g.get('dog'), 'σκύλος')
    
        def test_shall_toggle_from_fm_to_am(self):
        self.radio.toggle_amfm()
        state = self.radio.state.name
        expected_state_name = 'AM'
        self.assertEqual(state, expected_state_name)

    
        def test_display_current_time_at_current_time(self):
        '''
        Just as justification for working example with the time provider used in
        production. (Will always pass.)
        '''