from plone.app.testing import login from plone.app.testing import PLONE_FIXTURE from plone.app.testing import ploneSite from plone.app.testing import setRoles from plone.app.testing import TEST_USER_ID from plone.app.testing import TEST_USER_NAME from plone.app.testing import TEST_USER_PASSWORD from plone.namedfile.file import NamedImage from plone.testing import z2 from Products.Archetypes.interfaces import IBaseObject from Products.CMFCore.utils import getToolByName from six import StringIO from zope.configuration import xmlconfig B64_DATA = 'R0lGODlhAQABAIAAAAUEBAAAACwAAAAAAQABAAACAkQBADs=' GIF = StringIO(decodestring(B64_DATA)) GIF.filename = 'sample.gif' GIF.contentType = 'image/gif' GIF._width = 1 GIF._height = 1 def create(container, type_name, **kwargs): """A easy helper method to create some content since we do not have plone.api in core. """ new_id = container.invokeFactory(type_name, **kwargs) content = container[new_id] # Archetypes specific code was taken from ``plone.api``
def _rest_request(self, path, method='GET', args=None, body=None, \ headers=None, optionalpassword=None, providerheader=None): """Rest request main function :param path: path within tree :type path: str :param method: method to be implemented :type method: str :param args: the arguments for method :type args: dict :param body: body payload for the rest call :type body: dict :param headers: provide additional headers :type headers: dict :param optionalpassword: provide password for authentication :type optionalpassword: str :param provideheader: provider id for the header :type providerheader: str :returns: returns a RestResponse object """ files = None request_args = {} external_uri = True if 'redfish.dmtf.org' in path else False headers = {} if external_uri else self._get_req_headers(headers, providerheader, \ optionalpassword) reqpath = path.replace('//', '/') if not external_uri else path if body is not None: if body and isinstance(body, list) and isinstance(body[0], tuple): files = body body = None elif isinstance(body, (dict, list)): headers['Content-Type'] = 'application/json' body = json.dumps(body) elif not files: headers['Content-Type'] = 'application/x-www-form-urlencoded' body = urlencode(body) if method == 'PUT': resp = self._rest_request(method='HEAD', path=path) try: if resp.getheader('content-encoding') == 'gzip': buf = StringIO() gfile = gzip.GzipFile(mode='wb', fileobj=buf) try: gfile.write(str(body)) finally: gfile.close() compresseddata = buf.getvalue() if compresseddata: data = bytearray() data.extend(memoryview(compresseddata)) body = data except BaseException as excp: LOGGER.error('Error occur while compressing body: %s', excp) raise if args: if method == 'GET': reqpath += '?' + urlencode(args) elif method == 'PUT' or method == 'POST' or method == 'PATCH': headers['Content-Type'] = 'application/x-www-form-urlencoded' body = urlencode(args) restreq = RestRequest(path, method, data=files if files else body, \ url=self.base_url) attempts = 1 restresp = None while attempts <= self.MAX_RETRY: if LOGGER.isEnabledFor(logging.DEBUG): try: logbody = None if restreq.body: if restreq.body[0] == '{': logbody = restreq.body else: raise KeyError() if restreq.method in ['POST', 'PATCH']: debugjson = json.loads(restreq.body) if 'Password' in debugjson.keys(): debugjson['Password'] = '******' if 'OldPassword' in debugjson.keys(): debugjson['OldPassword'] = '******' if 'NewPassword' in debugjson.keys(): debugjson['NewPassword'] = '******' logbody = json.dumps(debugjson) LOGGER.debug('HTTP REQUEST: %s\n\tPATH: %s\n\t'\ 'HEADERS: %s\n\tBODY: %s', restreq.method, restreq.path, headers, \ logbody) except: LOGGER.debug('HTTP REQUEST: %s\n\tPATH: %s\n\tBODY: %s', restreq.method, \ restreq.path, 'binary body') LOGGER.info('Attempt %s of %s', attempts, path) try: while True: if self._conn is None or external_uri: self.__init_connection(proxy=external_uri) inittime = time.time() reqfullpath = self.base_url+reqpath if not external_uri else reqpath request_args['headers'] = headers if files: request_args['fields'] = files else: request_args['body'] = body resp = self._conn(method, reqfullpath, **request_args) self._conn_count += 1 endtime = time.time() LOGGER.info('Response Time to %s: %s seconds.', restreq.path, \ str(endtime-inittime)) if resp.status not in list(range(300, 399)) or resp.status == 304: break newloc = resp.headers.get('location') newurl = urlparse(newloc) reqpath = newurl.path self.__init_connection(newurl, proxy=external_uri) restresp = RestResponse(restreq, resp) except Exception as excp: attempts = attempts + 1 LOGGER.info('Retrying %s [%s]', path, excp) time.sleep(1) self.__init_connection(proxy=external_uri) continue else: break if attempts <= self.MAX_RETRY: if LOGGER.isEnabledFor(logging.DEBUG): headerstr = '' if restresp is not None: respheader = restresp.getheaders() for kiy, headerval in respheader.items(): headerstr += '\t' + kiy + ': ' + headerval + '\n' try: LOGGER.debug('HTTP RESPONSE for %s:\nCode:%s\nHeaders:'\ '\n%s\nBody Response of %s: %s', restresp.request.path,\ str(restresp._http_response.status)+ ' ' + \ restresp._http_response.reason, \ headerstr, restresp.request.path, restresp.read\ .encode('ascii', 'ignore')) except: LOGGER.debug('HTTP RESPONSE:\nCode:%s', restresp) else: LOGGER.debug('HTTP RESPONSE: No HTTP Response obtained') return restresp else: raise RetriesExhaustedError()
def __init__(self, response_str): self._file = StringIO(response_str)
def test_capability_without_tty(): """Assert capability templates are '' when stream is not a tty.""" t = TestTerminal(stream=StringIO()) eq_(t.save, u'') eq_(t.red, u'')
def do(status, repository, balancer): # stdout is process local in Python, so we can simply use this # to redirect all output from GerMake to a string sys.stdout = StringIO() C = Ansi2HTMLConverter() with balancer: try: is_overview = self.name.endswith("overview") lan_path = Path(self.repository.path) / "languages.json" if not lan_path.exists(): i = {"error": "The languages.json file is missing."} else: try: i = json.loads(lan_path.open().read()) except: i = { "error": "The languages.json file is corrupt." } else: missing = [] for e in ["languages"]: if e not in i: missing.append(e) if len(missing) > 0: i["error"] = "Some important entries are missing: " + \ ", ".join(missing) + "." #TODO do this right, i.e.: Why copyifnecessary? if is_overview: copyifnecessary( lan_path, Path(self.repository.path) / self.contest / "languages.json") comp = GerMake( repository.path + "/" + self.contest, task=self.name if not is_overview else "NO_TASK", no_test=True, submission=None, no_latex=False, safe_latex=True, language=self.language, clean=False, minimal=True) with repository: comp.prepare() # TODO Kommentieren! credentials_file = (Path(repository.path) / self.contest / "build" / "users.py") credentials_file.write_text('') f = None if is_overview: if self.language == "ALL": languages = i["languages"] elif self.language is None: raise NotImplementedError else: languages = [self.language] print(languages) def f(contestconfig): for l in languages: contestconfig.user("[user-{}]".format(l), "[password]", "Jane", "Doe", group=MyGroup( "dummy", 0, 0, 0, 0, None), primary_statements=[l]) #If self.language is None, this is the primary statement. #If self.language is ALL, this is _a list_ of all statements. #Else, it's the task statement associated with that language. pdf_file = comp.build(extra_conf_f=f) if is_overview: filename = "overview-sheets-for-" + self.language + ".pdf" pdf_file = str( Path(self.repository.path) / self.contest / "build" / "overview" / ".overviews-per-language" / filename) if pdf_file is None: status["error"] = True status["msg"] = "No statement found" else: result = None if self.language == "ALL": pdfmerger = PdfFileMerger() for s in pdf_file: pdfmerger.append(s) pdf_file = str( Path(self.repository.path) / self.contest / "build" / self.name / "statement-ALL.pdf") pdfmerger.write(pdf_file) pdfmerger.close() with open(pdf_file, "rb") as f: result = f.read() status["result"] = result except Exception: status["error"] = True status["msg"] = \ C.convert("\n".join(format_exception(*exc_info()))) sys.stdout.flush() status["log"] = C.convert(sys.stdout.getvalue()) status["done"] = True
def test_no_job_applying_tests(self): out = StringIO() sys.stdout = out call_command("send_test_reminder", stdout=out) self.assertEqual("False\n", out.getvalue())
def test_null_callable_numeric_colors(): """``color(n)`` should be a no-op on null terminals.""" t = TestTerminal(stream=StringIO()) eq_(t.color(5)('smoo'), 'smoo') eq_(t.on_color(6)('smoo'), 'smoo')
def __repr__(self): str_buffer = StringIO() self._pprint_impl(0, str_buffer) contents = str_buffer.getvalue() str_buffer.close() return contents
def check_schema(name, file_contents): """Check a Spack YAML schema against some data""" f = StringIO(file_contents) data = syaml.load_config(f) spack.config.validate(data, name)
def test_server_type_check(self): hosts = [('127.0.0.1', 6010), ('127.0.0.1', 6011), ('127.0.0.1', 6012)] # sample json response from http://<host>:<port>/ responses = { 6010: 'object-server', 6011: 'container-server', 6012: 'account-server' } def mock_scout_server_type(app, host): url = 'http://%s:%s/' % (host[0], host[1]) response = responses[host[1]] status = 200 return url, response, status stdout = StringIO() res_object = 'Invalid: http://127.0.0.1:6010/ is object-server' res_container = 'Invalid: http://127.0.0.1:6011/ is container-server' res_account = 'Invalid: http://127.0.0.1:6012/ is account-server' valid = "1/1 hosts ok, 0 error[s] while checking hosts." # Test for object server type - default with mock.patch('swift.cli.recon.Scout.scout_server_type', mock_scout_server_type), \ mock.patch('sys.stdout', new=stdout): self.recon.server_type_check(hosts) output = stdout.getvalue() self.assertTrue(res_container in output.splitlines()) self.assertTrue(res_account in output.splitlines()) stdout.truncate(0) # Test ok for object server type - default with mock.patch('swift.cli.recon.Scout.scout_server_type', mock_scout_server_type), \ mock.patch('sys.stdout', new=stdout): self.recon.server_type_check([hosts[0]]) output = stdout.getvalue() self.assertTrue(valid in output.splitlines()) stdout.truncate(0) # Test for account server type with mock.patch('swift.cli.recon.Scout.scout_server_type', mock_scout_server_type), \ mock.patch('sys.stdout', new=stdout): self.recon.server_type = 'account' self.recon.server_type_check(hosts) output = stdout.getvalue() self.assertTrue(res_container in output.splitlines()) self.assertTrue(res_object in output.splitlines()) stdout.truncate(0) # Test ok for account server type with mock.patch('swift.cli.recon.Scout.scout_server_type', mock_scout_server_type), \ mock.patch('sys.stdout', new=stdout): self.recon.server_type = 'account' self.recon.server_type_check([hosts[2]]) output = stdout.getvalue() self.assertTrue(valid in output.splitlines()) stdout.truncate(0) # Test for container server type with mock.patch('swift.cli.recon.Scout.scout_server_type', mock_scout_server_type), \ mock.patch('sys.stdout', new=stdout): self.recon.server_type = 'container' self.recon.server_type_check(hosts) output = stdout.getvalue() self.assertTrue(res_account in output.splitlines()) self.assertTrue(res_object in output.splitlines()) stdout.truncate(0) # Test ok for container server type with mock.patch('swift.cli.recon.Scout.scout_server_type', mock_scout_server_type), \ mock.patch('sys.stdout', new=stdout): self.recon.server_type = 'container' self.recon.server_type_check([hosts[1]]) output = stdout.getvalue() self.assertTrue(valid in output.splitlines())
def parse_string(self, string): return self.parse(StringIO(string))
def test_quarantine_check(self): hosts = [('127.0.0.1', 6010), ('127.0.0.1', 6020), ('127.0.0.1', 6030), ('127.0.0.1', 6040), ('127.0.0.1', 6050)] # sample json response from http://<host>:<port>/recon/quarantined responses = { 6010: { 'accounts': 0, 'containers': 0, 'objects': 1, 'policies': { '0': { 'objects': 0 }, '1': { 'objects': 1 } } }, 6020: { 'accounts': 1, 'containers': 1, 'objects': 3, 'policies': { '0': { 'objects': 1 }, '1': { 'objects': 2 } } }, 6030: { 'accounts': 2, 'containers': 2, 'objects': 5, 'policies': { '0': { 'objects': 2 }, '1': { 'objects': 3 } } }, 6040: { 'accounts': 3, 'containers': 3, 'objects': 7, 'policies': { '0': { 'objects': 3 }, '1': { 'objects': 4 } } }, # A server without storage policies enabled 6050: { 'accounts': 0, 'containers': 0, 'objects': 4 } } # <low> <high> <avg> <total> <Failed> <no_result> <reported> expected = { 'objects_0': (0, 3, 1.5, 6, 0.0, 0, 4), 'objects_1': (1, 4, 2.5, 10, 0.0, 0, 4), 'objects': (1, 7, 4.0, 20, 0.0, 0, 5), 'accounts': (0, 3, 1.2, 6, 0.0, 0, 5), 'containers': (0, 3, 1.2, 6, 0.0, 0, 5) } def mock_scout_quarantine(app, host): url = 'http://%s:%s/recon/quarantined' % host response = responses[host[1]] status = 200 return url, response, status, 0, 0 stdout = StringIO() with mock.patch('swift.cli.recon.Scout.scout', mock_scout_quarantine), \ mock.patch('sys.stdout', new=stdout): self.recon_instance.quarantine_check(hosts) output = stdout.getvalue() r = re.compile("\[quarantined_(.*)\](.*)") for line in output.splitlines(): m = r.match(line) if m: ex = expected.pop(m.group(1)) self.assertEqual( m.group(2), " low: %s, high: %s, avg: %s, total: %s," " Failed: %s%%, no_result: %s, reported: %s" % ex) self.assertFalse(expected)
def __init__(self, buildername='html', testroot=None, srcdir=None, freshenv=False, confoverrides=None, status=None, warning=None, tags=None, docutilsconf=None): if testroot is None: defaultsrcdir = 'root' testroot = rootdir / 'root' else: defaultsrcdir = 'test-' + testroot testroot = rootdir / 'roots' / ('test-' + testroot) if srcdir is None: srcdir = tempdir / defaultsrcdir else: srcdir = tempdir / srcdir if not srcdir.exists(): testroot.copytree(srcdir) if docutilsconf is not None: (srcdir / 'docutils.conf').write_text(docutilsconf) builddir = srcdir / '_build' # if confdir is None: confdir = srcdir # if outdir is None: outdir = builddir.joinpath(buildername) if not outdir.isdir(): outdir.makedirs() # if doctreedir is None: doctreedir = builddir.joinpath('doctrees') if not doctreedir.isdir(): doctreedir.makedirs() if confoverrides is None: confoverrides = {} if status is None: status = StringIO() if warning is None: warning = ListOutput('stderr') # if warningiserror is None: warningiserror = False self._saved_path = sys.path[:] self._saved_directives = directives._directives.copy() self._saved_roles = roles._roles.copy() self._saved_nodeclasses = set(v for v in dir(nodes.GenericNodeVisitor) if v.startswith('visit_')) try: application.Sphinx.__init__(self, srcdir, confdir, outdir, doctreedir, buildername, confoverrides, status, warning, freshenv, warningiserror, tags) except: self.cleanup() raise
# -*- coding: utf-8 -*- """ test_sphinx ~~~~~~~~~~~ General Sphinx test and check output. """ import re from six import StringIO from util import path, with_app srcdir = path(__file__).parent.joinpath('sphinx').abspath() warnfile = StringIO() def teardown_module(): (srcdir / '_build').rmtree(True) @with_app(srcdir=srcdir, warning=warnfile) def test_sphinx(app): app.builder.build_all() warnings = warnfile.getvalue() assert re.search(u'could not relabel citation \\[Test01\\]', warnings) assert re.search(u'could not relabel citation \\[Test02\\]', warnings) assert re.search(u'could not relabel citation \\[Wa04\\]', warnings) assert re.search(u'could not relabel citation reference \\[Test01\\]', warnings) assert re.search(u'could not relabel citation reference \\[Test02\\]',
"editable (development) source trees." % (CACHE_FILE, )) sys.exit() if len(sys.argv) > 1: LX_SET = range(*tuple(int(i) for i in sys.argv[1].split(':'))) else: LX_SET = range(1, 24) if len(sys.argv) > 2: COUNT = int(sys.argv[2]) else: COUNT = None for lx in LX_SET: local_count = COUNT if COUNT else 10000 * lx cond, pset, mat = generate_quadratic_rom_geometry(lx, local_count) if pset is not None: txt = StringIO() np.savetxt(txt, pset) GeometryCache[lx] = (cond, txt.getvalue()) with open(CACHE_FILE, 'w') as FILE: FILE.write(""" # ___________________________________________________________________________ # # Pyomo: Python Optimization Modeling Objects # Copyright 2017 National Technology and Engineering Solutions of Sandia, LLC # Under the terms of Contract DE-NA0003525 with National Technology and # Engineering Solutions of Sandia, LLC, the U.S. Government retains certain # rights in this software. # This software is distributed under the 3-clause BSD License. # ___________________________________________________________________________ # # Cache of autogenerated quadratic ROM geometries
def test_multiple_extension(): content = StringIO(""" <?xml version="1.0"?> <wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/"> <wsdl:types> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://tests.python-zeep.org/a" targetNamespace="http://tests.python-zeep.org/a" xmlns:b="http://tests.python-zeep.org/b" elementFormDefault="qualified"> <xs:import namespace="http://tests.python-zeep.org/b"/> <xs:complexType name="type_a"> <xs:complexContent> <xs:extension base="b:type_b"/> </xs:complexContent> </xs:complexType> <xs:element name="typetje" type="tns:type_a"/> </xs:schema> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://tests.python-zeep.org/b" targetNamespace="http://tests.python-zeep.org/b" xmlns:c="http://tests.python-zeep.org/c" elementFormDefault="qualified"> <xs:import namespace="http://tests.python-zeep.org/c"/> <xs:complexType name="type_b"> <xs:complexContent> <xs:extension base="c:type_c"/> </xs:complexContent> </xs:complexType> </xs:schema> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://tests.python-zeep.org/c" targetNamespace="http://tests.python-zeep.org/c" elementFormDefault="qualified"> <xs:complexType name="type_c"> <xs:complexContent> <xs:extension base="tns:type_d"/> </xs:complexContent> </xs:complexType> <xs:complexType name="type_d"> <xs:attribute name="wat" type="xs:string" /> </xs:complexType> </xs:schema> </wsdl:types> </wsdl:definitions> """.strip()) document = wsdl.Document(content, None) type_a = document.types.get_type('ns0:type_a') type_a(wat='x')
def test_run_command_on_right_date(self): out = StringIO() sys.stdout = out call_command("send_weekly_summary", stdout=out) self.assertEqual("True\n", out.getvalue())
def test_import_schema_without_location(recwarn): content = StringIO(""" <?xml version="1.0"?> <wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:b="http://tests.python-zeep.org/b" xmlns:c="http://tests.python-zeep.org/c" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" targetNamespace="http://tests.python-zeep.org/transient" xmlns:tns="http://tests.python-zeep.org/transient"> <wsdl:types> <xsd:schema> <xsd:import namespace="http://tests.python-zeep.org/a" schemaLocation="a.xsd"/> </xsd:schema> <xsd:schema targetNamespace="http://tests.python-zeep.org/c"> <xsd:element name="bar" type="b:foo"/> </xsd:schema> </wsdl:types> <wsdl:message name="method"> <wsdl:part name="param" element="c:bar"/> </wsdl:message> <wsdl:portType name="port_type"> <wsdl:operation name="method" parameterOrder="param"> <wsdl:input message="tns:method" /> </wsdl:operation> </wsdl:portType> <wsdl:binding name="binding" type="tns:port_type" > <soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http" /> <wsdl:operation name="method" > <soap:operation soapAction="method"/> <wsdl:input> <soap:body use="literal" /> </wsdl:input> </wsdl:operation> </wsdl:binding> </wsdl:definitions> """.strip()) schema_node_a = etree.fromstring(""" <?xml version="1.0"?> <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://tests.python-zeep.org/a" targetNamespace="http://tests.python-zeep.org/a" xmlns:b="http://tests.python-zeep.org/b" elementFormDefault="qualified"> <xsd:import namespace="http://tests.python-zeep.org/b" schemaLocation="b.xsd"/> </xsd:schema> """.strip()) schema_node_b = etree.fromstring(""" <?xml version="1.0"?> <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://tests.python-zeep.org/b" targetNamespace="http://tests.python-zeep.org/b" elementFormDefault="qualified"> <xsd:complexType name="foo"> <xsd:sequence> <xsd:element name="item_1" type="xsd:string"/> </xsd:sequence> </xsd:complexType> </xsd:schema> """.strip()) transport = DummyTransport() transport.bind('a.xsd', schema_node_a) transport.bind('b.xsd', schema_node_b) document = wsdl.Document(content, transport) assert len(recwarn) == 0 assert document.types.get_type('{http://tests.python-zeep.org/b}foo')
def test_null_location(): """Make sure ``location()`` with no args just does position restoration.""" t = TestTerminal(stream=StringIO(), force_styling=True) with t.location(): pass eq_(t.stream.getvalue(), unicode_cap('sc') + unicode_cap('rc'))
def test_wsdl_import_xsd_references(recwarn): wsdl_main = StringIO(""" <?xml version="1.0"?> <wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://tests.python-zeep.org/xsd-main" xmlns:sec="http://tests.python-zeep.org/wsdl-secondary" xmlns:xsd-sec="http://tests.python-zeep.org/xsd-secondary" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/" targetNamespace="http://tests.python-zeep.org/xsd-main"> <wsdl:import namespace="http://tests.python-zeep.org/wsdl-secondary" location="http://tests.python-zeep.org/schema-2.wsdl"/> <wsdl:types> <xsd:schema targetNamespace="http://tests.python-zeep.org/xsd-main" xmlns:tns="http://tests.python-zeep.org/xsd-main"> <xsd:element name="input" type="xsd:string"/> </xsd:schema> </wsdl:types> <wsdl:message name="message-1"> <wsdl:part name="response" element="tns:input"/> </wsdl:message> <wsdl:message name="message-2"> <wsdl:part name="response" element="xsd-sec:input2"/> </wsdl:message> <wsdl:portType name="TestPortType"> <wsdl:operation name="TestOperation1"> <wsdl:input message="message-1"/> </wsdl:operation> <wsdl:operation name="TestOperation2"> <wsdl:input message="sec:message-2"/> </wsdl:operation> </wsdl:portType> <wsdl:binding name="TestBinding" type="tns:TestPortType"> <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/> <wsdl:operation name="TestOperation1"> <soap:operation soapAction=""/> <wsdl:input> <soap:body use="literal"/> </wsdl:input> </wsdl:operation> <wsdl:operation name="TestOperation2"> <soap:operation soapAction=""/> <wsdl:input> <soap:body use="literal"/> </wsdl:input> </wsdl:operation> </wsdl:binding> <wsdl:service name="TestService"> <wsdl:documentation>Test service</wsdl:documentation> <wsdl:port name="TestPortType" binding="tns:TestBinding"> <soap:address location="http://tests.python-zeep.org/test"/> </wsdl:port> </wsdl:service> </wsdl:definitions> """.strip()) wsdl_2 = (""" <?xml version="1.0"?> <wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://tests.python-zeep.org/wsdl-secondary" xmlns:mine="http://tests.python-zeep.org/xsd-secondary" xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/" targetNamespace="http://tests.python-zeep.org/wsdl-secondary"> <wsdl:types> <xsd:schema targetNamespace="http://tests.python-zeep.org/xsd-secondary" xmlns:tns="http://tests.python-zeep.org/xsd-secondary"> <xsd:element name="input2" type="xsd:string"/> </xsd:schema> </wsdl:types> <wsdl:message name="message-2"> <wsdl:part name="response" element="mine:input2"/> </wsdl:message> </wsdl:definitions> """.strip()) transport = DummyTransport() transport.bind('http://tests.python-zeep.org/schema-2.wsdl', wsdl_2) document = wsdl.Document(wsdl_main, transport) document.dump()
def test_init_descriptor_always_initted(): """We should be able to get a height and width even on no-tty Terminals.""" t = Terminal(stream=StringIO()) eq_(type(t.height), int)
def scalars_impl(self, tag, run, experiment, output_format): """Result of the form `(body, mime_type)`.""" if self._data_provider: # Downsample reads to 1000 scalars per time series, which is the # default size guidance for scalars under the multiplexer loading # logic. SAMPLE_COUNT = 1000 all_scalars = self._data_provider.read_scalars( experiment_id=experiment, plugin_name=metadata.PLUGIN_NAME, downsample=SAMPLE_COUNT, run_tag_filter=provider.RunTagFilter(runs=[run], tags=[tag]), ) scalars = all_scalars.get(run, {}).get(tag, None) if scalars is None: raise ValueError('No scalar data for run=%r, tag=%r' % (run, tag)) values = [(x.wall_time, x.step, x.value) for x in scalars] elif self._db_connection_provider: db = self._db_connection_provider() # We select for steps greater than -1 because the writer inserts # placeholder rows en masse. The check for step filters out those rows. cursor = db.execute( ''' SELECT Tensors.step, Tensors.computed_time, Tensors.data, Tensors.dtype FROM Tensors JOIN Tags ON Tensors.series = Tags.tag_id JOIN Runs ON Tags.run_id = Runs.run_id WHERE /* For backwards compatibility, ignore the experiment id for matching purposes if it is empty. */ (:exp == '' OR Runs.experiment_id == CAST(:exp AS INT)) AND Runs.run_name = :run AND Tags.tag_name = :tag AND Tags.plugin_name = :plugin AND Tensors.shape = '' AND Tensors.step > -1 ORDER BY Tensors.step ''', dict(exp=experiment, run=run, tag=tag, plugin=metadata.PLUGIN_NAME)) values = [(wall_time, step, self._get_value(data, dtype_enum)) for (step, wall_time, data, dtype_enum) in cursor] else: tensor_events = self._multiplexer.Tensors(run, tag) values = [ (tensor_event.wall_time, tensor_event.step, tensor_util.make_ndarray(tensor_event.tensor_proto).item()) for tensor_event in tensor_events ] if output_format == OutputFormat.CSV: string_io = StringIO() writer = csv.writer(string_io) writer.writerow(['Wall time', 'Step', 'Value']) writer.writerows(values) return (string_io.getvalue(), 'text/csv') else: return (values, 'application/json')
def test_capability_with_forced_tty(): """If we force styling, capabilities had better not (generally) be empty.""" t = TestTerminal(stream=StringIO(), force_styling=True) eq_(t.save, unicode_cap('sc'))
def test_status_empty(): with pytest.raises(EOFError): StatusAndHeadersParser([], verify=False).parse(StringIO(''))
def _rest_request(self, path='', method="GET", args=None, body=None, headers=None, optionalpassword=None, providerheader=None): """Rest request for blob store client :param path: path within tree :type path: str :param method: method to be implemented :type method: str :param args: the arguments for method :type args: dict :param body: body payload for the rest call :type body: dict :param headers: provide additional headers :type headers: dict :param optionalpassword: provide password for authentication :type optionalpassword: str :param provideheader: provider id for the header :type providerheader: str :return: returns a RestResponse object """ self.updatecredentials() headers = self._get_req_headers(headers, providerheader, \ optionalpassword) reqpath = path.replace('//', '/') oribody = body if body is not None: if isinstance(body, (dict, list)): headers['Content-Type'] = 'application/json' body = json.dumps(body) else: headers['Content-Type'] = 'application/x-www-form-urlencoded' body = urlencode(body) if method == 'PUT': resp = self._rest_request(path=path) try: if resp.getheader('content-encoding') == 'gzip': buf = StringIO() gfile = gzip.GzipFile(mode='wb', fileobj=buf) try: gfile.write(str(body)) finally: gfile.close() compresseddata = buf.getvalue() if compresseddata: data = bytearray() data.extend(memoryview(compresseddata)) body = data except BaseException as excp: LOGGER.error('Error occur while compressing body: %s', excp) raise headers['Content-Length'] = len(body) if args: if method == 'GET': reqpath += '?' + urlencode(args) elif method == 'PUT' or method == 'POST' or method == 'PATCH': headers['Content-Type'] = 'application/x-www-form-urlencoded' body = urlencode(args) str1 = '{} {} {}\r\n'.format(method, reqpath, \ Blobstore2RestClient._http_vsn_str) str1 += 'Host: \r\n' str1 += 'Accept-Encoding: identity\r\n' for header, value in headers.items(): str1 += '{}: {}\r\n'.format(header, value) str1 += '\r\n' if body and len(body) > 0: if isinstance(body, bytearray): str1 = str1.encode("ASCII") + body else: str1 += body bs2 = BlobStore2() if not isinstance(str1, bytearray): str1 = str1.encode("ASCII") if LOGGER.isEnabledFor(logging.DEBUG): try: logbody = None if body: if body[0] == '{': logbody = body else: raise if method in ['POST', 'PATCH']: debugjson = json.loads(body) if 'Password' in debugjson.keys(): debugjson['Password'] = '******' if 'OldPassword' in debugjson.keys(): debugjson['OldPassword'] = '******' if 'NewPassword' in debugjson.keys(): debugjson['NewPassword'] = '******' logbody = json.dumps(debugjson) LOGGER.debug('Blobstore REQUEST: %s\n\tPATH: %s\n\tHEADERS: '\ '%s\n\tBODY: %s', method, str(headers), path, logbody) except: LOGGER.debug('Blobstore REQUEST: %s\n\tPATH: %s\n\tHEADERS: '\ '%s\n\tBODY: %s', method, str(headers), path, 'binary body') inittime = time.time() for idx in range(5): try: resp_txt = bs2.rest_immediate(str1) break except Blob2OverrideError as excp: if idx == 4: raise Blob2OverrideError(2) else: continue endtime = time.time() bs2.channel.close() LOGGER.info("iLO Response Time to %s: %s secs.", path, str(endtime-inittime)) #Dummy response to support a bad host response if len(resp_txt) == 0: resp_txt = "HTTP/1.1 500 Not Found\r\nAllow: " \ "GET\r\nCache-Control: no-cache\r\nContent-length: " \ "0\r\nContent-type: text/html\r\nDate: Tues, 1 Apr 2025 " \ "00:00:01 GMT\r\nServer: " \ "HP-iLO-Server/1.30\r\nX_HP-CHRP-Service-Version: 1.0.3\r\n\r\n\r\n" restreq = RestRequest(path, method, data=body, url=self.base_url) rest_response = RisRestResponse(restreq, resp_txt) if rest_response.status in range(300, 399) and \ rest_response.status != 304: newloc = rest_response.getheader("location") newurl = urlparse(newloc) rest_response = self._rest_request(newurl.path, method, args, \ oribody, headers, optionalpassword, \ providerheader) try: if rest_response.getheader('content-encoding') == 'gzip': if hasattr(gzip, "decompress"): rest_response.read = gzip.decompress(rest_response.ori) else: compressedfile = StringIO(rest_response.ori) decompressedfile = gzip.GzipFile(fileobj=compressedfile) rest_response.read = decompressedfile.read() except Exception: pass if LOGGER.isEnabledFor(logging.DEBUG): headerstr = '' headerget = rest_response.getheaders() for header in headerget: headerstr += '\t' + header + ': ' + headerget[header] + '\n' try: LOGGER.debug('Blobstore RESPONSE for %s:\nCode: %s\nHeaders:'\ '\n%s\nBody of %s: %s', rest_response.request.path,\ str(rest_response._http_response.status)+ ' ' + \ rest_response._http_response.reason, \ headerstr, rest_response.request.path, \ rest_response.read) except: LOGGER.debug('Blobstore RESPONSE for %s:\nCode:%s', \ rest_response.request.path, rest_response) return rest_response
def test_status_one_word(): res = StatusAndHeadersParser(['GET'], verify=False).parse(StringIO('A')) assert (str(res) == 'A\r\n')
from json import loads from xml.etree import ElementTree # Be sure to use Galaxy's vanilla pyparsing instead of the older version # imported by twill. import pyparsing # noqa: F401 import twill import twill.commands as tc from six import string_types, StringIO from six.moves.urllib.parse import urlencode, urlparse from twill.other_packages._mechanize_dist import ClientForm from base.testcase import FunctionalTestCase # Force twill to log to a buffer -- FIXME: Should this go to stdout and be captured by nose? buffer = StringIO() twill.set_output(buffer) tc.config('use_tidy', 0) # Dial ClientCookie logging down (very noisy) logging.getLogger("ClientCookie.cookies").setLevel(logging.WARNING) log = logging.getLogger(__name__) DEFAULT_TOOL_TEST_WAIT = os.environ.get("GALAXY_TEST_DEFAULT_WAIT", 86400) class TwillTestCase(FunctionalTestCase): """Class of FunctionalTestCase geared toward HTML interactions using the Twill library.""" def check_for_strings(self, strings_displayed=[], strings_not_displayed=[]):
def test_list_languages(self): output = StringIO() call_command('list_addons', stdout=output) self.assertIn('msgmerge', output.getvalue())
def setUp(self): """Replace stdin.""" super(ManagementCommandTestCase, self).setUp() self.stdin = sys.stdin sys.stdin = StringIO(SIMPLE_EMAIL_CONTENT.strip()) self.arm = factories.ARmessageFactory(mbox=self.account.mailbox)
def __init__(self): self.buffer = StringIO() self.handler_buffer = logging.StreamHandler(self.buffer) self.handler_buffer.setLevel(logging.INFO) self._suspended_handlers = []