How to use is_upper method in assertpy

Best Python code snippet using assertpy_python

db.py

Source:db.py Github

copy

Full Screen

1# -*- coding: utf-8 -*-2# -------------------------------------------------------------------------3# AppConfig configuration made easy. Look inside private/appconfig.ini4# Auth is for authenticaiton and access control5# -------------------------------------------------------------------------6from gluon.contrib.appconfig import AppConfig7from gluon.tools import Auth8# -------------------------------------------------------------------------9# This scaffolding model makes your app work on Google App Engine too10# File is released under public domain and you can use without limitations11# -------------------------------------------------------------------------12if request.global_settings.web2py_version < "2.15.5":13 raise HTTP(500, "Requires web2py 2.15.5 or newer")14# -------------------------------------------------------------------------15# if SSL/HTTPS is properly configured and you want all HTTP requests to16# be redirected to HTTPS, uncomment the line below:17# -------------------------------------------------------------------------18# request.requires_https()19# -------------------------------------------------------------------------20# once in production, remove reload=True to gain full speed21# -------------------------------------------------------------------------22configuration = AppConfig(reload=True)23if not request.env.web2py_runtime_gae:24 # ---------------------------------------------------------------------25 # if NOT running on Google App Engine use SQLite or other DB26 # ---------------------------------------------------------------------27 db = DAL(configuration.get('db.uri'),28 pool_size=configuration.get('db.pool_size'),29 migrate_enabled=configuration.get('db.migrate'),30 check_reserved=['all'])31else:32 # ---------------------------------------------------------------------33 # connect to Google BigTable (optional 'google:datastore://namespace')34 # ---------------------------------------------------------------------35 db = DAL('google:datastore+ndb')36 # ---------------------------------------------------------------------37 # store sessions and tickets there38 # ---------------------------------------------------------------------39 session.connect(request, response, db=db)40 # ---------------------------------------------------------------------41 # or store session in Memcache, Redis, etc.42 # from gluon.contrib.memdb import MEMDB43 # from google.appengine.api.memcache import Client44 # session.connect(request, response, db = MEMDB(Client()))45 # ---------------------------------------------------------------------46# -------------------------------------------------------------------------47# by default give a view/generic.extension to all actions from localhost48# none otherwise. a pattern can be 'controller/function.extension'49# -------------------------------------------------------------------------50response.generic_patterns = [] 51if request.is_local and not configuration.get('app.production'):52 response.generic_patterns.append('*')53# -------------------------------------------------------------------------54# choose a style for forms55# -------------------------------------------------------------------------56response.formstyle = 'bootstrap4_inline'57response.form_label_separator = ''58# -------------------------------------------------------------------------59# (optional) optimize handling of static files60# -------------------------------------------------------------------------61# response.optimize_css = 'concat,minify,inline'62# response.optimize_js = 'concat,minify,inline'63# -------------------------------------------------------------------------64# (optional) static assets folder versioning65# -------------------------------------------------------------------------66# response.static_version = '0.0.0'67# -------------------------------------------------------------------------68# Here is sample code if you need for69# - email capabilities70# - authentication (registration, login, logout, ... )71# - authorization (role based authorization)72# - services (xml, csv, json, xmlrpc, jsonrpc, amf, rss)73# - old style crud actions74# (more options discussed in gluon/tools.py)75# -------------------------------------------------------------------------76# host names must be a list of allowed host names (glob syntax allowed)77auth = Auth(db, host_names=configuration.get('host.names'))78# -------------------------------------------------------------------------79# create all tables needed by auth, maybe add a list of extra fields80# -------------------------------------------------------------------------81auth.settings.extra_fields['auth_user'] = []82auth.define_tables(username=False, signature=False)83# -------------------------------------------------------------------------84# configure email85# -------------------------------------------------------------------------86mail = auth.settings.mailer87mail.settings.server = 'logging' if request.is_local else configuration.get('smtp.server')88mail.settings.sender = configuration.get('smtp.sender')89mail.settings.login = configuration.get('smtp.login')90mail.settings.tls = configuration.get('smtp.tls') or False91mail.settings.ssl = configuration.get('smtp.ssl') or False92# -------------------------------------------------------------------------93# configure auth policy94# -------------------------------------------------------------------------95auth.settings.registration_requires_verification = False96auth.settings.registration_requires_approval = False97auth.settings.reset_password_requires_verification = True98# ------------------------------------------------------------------------- 99# read more at http://dev.w3.org/html5/markup/meta.name.html 100# -------------------------------------------------------------------------101response.meta.author = configuration.get('app.author')102response.meta.description = configuration.get('app.description')103response.meta.keywords = configuration.get('app.keywords')104response.meta.generator = configuration.get('app.generator')105response.show_toolbar = configuration.get('app.toolbar')106# -------------------------------------------------------------------------107# your http://google.com/analytics id 108# -------------------------------------------------------------------------109response.google_analytics_id = configuration.get('google.analytics_id')110# -------------------------------------------------------------------------111# maybe use the scheduler112# -------------------------------------------------------------------------113if configuration.get('scheduler.enabled'):114 from gluon.scheduler import Scheduler115 scheduler = Scheduler(db, heartbeat=configuration.get('scheduler.heartbeat'))116db.define_table('empresa',117 Field('proprietario','reference auth_user', label='Proprietario', writable=False, readable=False, notnull=True, default=1),118 Field('razaosocial', 'string', label='Razão Social',requires = IS_UPPER()),119 Field('nomefantasia', 'string', label='Nome Fantasia',requires = IS_UPPER()),120 Field('cnpj', 'string', label='CNPJ',default="00.000.000/0001-00",requires = IS_UPPER()),121 Field('inscricaoestarual', 'string',default="00000", label='Insc. Est',requires = IS_UPPER()),122 Field('inscricaomunicipal', 'string',default="00000", label='Insc. Mun',requires = IS_UPPER()),123 Field('crt', 'string', label='CRT',default="00000",requires = IS_UPPER()),124 #endereco125 Field('cep', 'string', label='CEP',default="60000-000",requires = IS_UPPER()),126 Field('lougradouro', 'string', label='Lougradouro',default="Rua",requires = IS_UPPER()),127 Field('numero', 'string', label='Numero',default="0",requires = IS_UPPER()),128 Field('bairro', 'string', label='Bairro',default="Centro",requires = IS_UPPER()),129 Field('uf', 'string', label='UF',default="CE",requires = IS_UPPER()),130 Field('cidade', 'string', label='Cidade', default='Juazeiro do Norte',requires = IS_UPPER()),131 Field('complemento', 'string', label='Complemento',default="Sem Complemento",requires = IS_UPPER()),132 #contato133 Field('email', 'string', label='Email',default="sem@email.com",requires = IS_UPPER()),134 Field('telefone', 'string', label='Telefone',default="(88)3500-0000",requires = IS_UPPER()),135 Field('celular', 'string', label='Celular',default="(88)99000-0000",requires = IS_UPPER()),136 #quantidade dependendo do pacote que contrate137 Field('limite_clientes', 'integer', label='L Clientes', writable=False, readable=False, default=1000),138 Field('limite_logins', 'integer', label='L Logins', writable=False, readable=False, default=4),139 Field('limite_produtos', 'integer', label='L Produtos', writable=False, readable=False, default=200),140 Field('limite_fornecedores', 'integer', label='L Fornecedores', writable=False, readable=False, default=200),141 Field('limite_vendas', 'integer', label='L Vendas', writable=False, readable=False, default=2000),142 Field('data_bloqueio', 'date', label="Data Bloqueio", writable=False, readable=False, default=request.now, requires = IS_DATE(format=('%d-%m-%Y')), notnull=True),143 Field('ativo', 'boolean', writable=False, readable=False, default=True),144 auth.signature,145 format='%(nomefantasia)s')146db.define_table('usuario_empresa',147 Field('usuario','reference auth_user', writable=False, readable=False, label='Usuario'),148 Field('empresa','reference empresa', writable=False, readable=False, label='empresa'),149 Field('nome', 'string', label='Nome',requires = IS_UPPER()),150 Field('tipo', 'string', label='tipo',default='Representante'),151 Field('comissao', 'double', label='%Comissão', writable=True, readable=True, notnull=True, default=10),152 Field('ativo', 'boolean', writable=False, readable=False, default=True),153 format='%(nome)s')154db.define_table('pessoa',155 Field('empresa','reference empresa', label='empresa', writable=False, readable=False),156 Field('representante','reference usuario_empresa', writable=True, readable=True, label='Representante'),157 Field('tipo', 'string', label='Tipo', writable=False, readable=False, default='Física',requires = IS_UPPER()),158 Field('razaosocial_nome', 'string', label='RS/NC',notnull=True ,requires=[IS_UPPER(),IS_LENGTH(minsize=12, error_message='Nome muito pequeno')]),159 Field('sexo', 'string', label='Sexo', default='M',notnull=True, writable=False, readable=False ,requires = IS_UPPER()),160 Field('estado_civil', 'string', label='Est. Civil',notnull=True , writable=False, readable=False, default='Solteiro(a)',requires = IS_UPPER()),161 Field('apelido_nome_fantasia', 'string', label='AP/NF', writable=False, readable=False,requires = IS_UPPER()),162 Field('cpf', 'string', label='CPF/CNPJ',notnull=True ,requires = IS_UPPER()),163 Field('org_espedidor_cpf', 'string', default='SSP', writable=False, readable=False,notnull=True , label='org esp.',requires = IS_UPPER()),164 Field('rg', 'string', label='RG',notnull=True ,requires = IS_UPPER()),165 Field('org_espedidor_rg', 'string', default='SSP', writable=False, readable=False,notnull=True , label='org esp.',requires = IS_UPPER()),166 Field('cep', 'string', label='CEP', default='63050-000',requires = IS_UPPER()),167 Field('lougradouro', 'string', label='Lougradouro',requires = IS_UPPER()),168 Field('numero', 'string', label='Numero',requires = IS_UPPER()),169 Field('bairro', 'string', default='Centro', label='Bairro',requires = IS_UPPER()),170 Field('uf', 'string', label='UF', default='CE',requires = IS_UPPER()),171 Field('cidade', 'string', label='Cidade', default='Juazeiro do Norte',requires = IS_UPPER()),172 Field('complemento', 'string', label='Complemento',requires = IS_UPPER()),173 Field('email', 'string', label='Email', default='sem@email.com',requires = IS_EMAIL(error_message='Email Invalido!')),174 Field('telefone', 'string', label='Telefone', default='(88)3555-5555',requires = IS_UPPER()),175 Field('celular', 'string',notnull=True , default='(88)98888-8888', label='Celular',requires = IS_UPPER()),176 Field('ativo', 'boolean', writable=False, readable=False, default=True),177 auth.signature,178 format='%(razaosocial_nome)s')179db.define_table('fornecedor',180 Field('empresa','reference empresa', writable=False, readable=False, label='empresa'),181 Field('nome', 'string', label='Nome',requires = IS_UPPER()),182 Field('descricao', 'string', label='Descrição',requires = IS_UPPER()),183 Field('telefone', 'string', label='Telefone',default="(88)3500-0000",requires = IS_UPPER()),184 Field('celular', 'string', label='Celular',default="(88)99000-0000",requires = IS_UPPER()),185 Field('total_compra', 'double', label='Total Compras', writable=False, readable=False, notnull=True, default=0),186 Field('total_pago', 'double', label='Total Pago', writable=False, readable=False, notnull=True, default=0),187 Field('total_devolvido', 'double', label='Total Devolvido', writable=False, readable=False, notnull=True, default=0),188 Field('ativo', 'boolean', writable=False, readable=False, default=True),189 auth.signature,190 format='%(nome)s')191db.define_table('produto',192 Field('empresa','reference empresa', writable=False, readable=False, label='Empresa'),193 Field('fornecedor','reference fornecedor', writable=True, readable=True, label='Fornecedor'),194 Field('descricao', 'string', label='Descrição',requires = IS_UPPER()),195 Field('quant_estoque', 'integer', label='Q Estoque', writable=False, readable=False, default=0),196 Field('custo_unitario', 'double', label='Custo Unitario', writable=True, readable=True, notnull=True, default=0),197 Field('preco_unitario', 'double', label='Preço Unitario', writable=True, readable=True, notnull=True, default=0),198 Field('ativo', 'boolean', writable=False, readable=False, default=True),199 auth.signature,...

Full Screen

Full Screen

test_decompositions.py

Source:test_decompositions.py Github

copy

Full Screen

1from sympy import Rational, I, expand_mul, S, simplify2from sympy.matrices.matrices import NonSquareMatrixError3from sympy.matrices import Matrix, zeros, eye, SparseMatrix4from sympy.abc import x, y, z5from sympy.testing.pytest import raises6from sympy.testing.matrices import allclose7def test_LUdecomp():8 testmat = Matrix([[0, 2, 5, 3],9 [3, 3, 7, 4],10 [8, 4, 0, 2],11 [-2, 6, 3, 4]])12 L, U, p = testmat.LUdecomposition()13 assert L.is_lower14 assert U.is_upper15 assert (L*U).permute_rows(p, 'backward') - testmat == zeros(4)16 testmat = Matrix([[6, -2, 7, 4],17 [0, 3, 6, 7],18 [1, -2, 7, 4],19 [-9, 2, 6, 3]])20 L, U, p = testmat.LUdecomposition()21 assert L.is_lower22 assert U.is_upper23 assert (L*U).permute_rows(p, 'backward') - testmat == zeros(4)24 # non-square25 testmat = Matrix([[1, 2, 3],26 [4, 5, 6],27 [7, 8, 9],28 [10, 11, 12]])29 L, U, p = testmat.LUdecomposition(rankcheck=False)30 assert L.is_lower31 assert U.is_upper32 assert (L*U).permute_rows(p, 'backward') - testmat == zeros(4, 3)33 # square and singular34 testmat = Matrix([[1, 2, 3],35 [2, 4, 6],36 [4, 5, 6]])37 L, U, p = testmat.LUdecomposition(rankcheck=False)38 assert L.is_lower39 assert U.is_upper40 assert (L*U).permute_rows(p, 'backward') - testmat == zeros(3)41 M = Matrix(((1, x, 1), (2, y, 0), (y, 0, z)))42 L, U, p = M.LUdecomposition()43 assert L.is_lower44 assert U.is_upper45 assert (L*U).permute_rows(p, 'backward') - M == zeros(3)46 mL = Matrix((47 (1, 0, 0),48 (2, 3, 0),49 ))50 assert mL.is_lower is True51 assert mL.is_upper is False52 mU = Matrix((53 (1, 2, 3),54 (0, 4, 5),55 ))56 assert mU.is_lower is False57 assert mU.is_upper is True58 # test FF LUdecomp59 M = Matrix([[1, 3, 3],60 [3, 2, 6],61 [3, 2, 2]])62 P, L, Dee, U = M.LUdecompositionFF()63 assert P*M == L*Dee.inv()*U64 M = Matrix([[1, 2, 3, 4],65 [3, -1, 2, 3],66 [3, 1, 3, -2],67 [6, -1, 0, 2]])68 P, L, Dee, U = M.LUdecompositionFF()69 assert P*M == L*Dee.inv()*U70 M = Matrix([[0, 0, 1],71 [2, 3, 0],72 [3, 1, 4]])73 P, L, Dee, U = M.LUdecompositionFF()74 assert P*M == L*Dee.inv()*U75 # issue 1579476 M = Matrix(77 [[1, 2, 3],78 [4, 5, 6],79 [7, 8, 9]]80 )81 raises(ValueError, lambda : M.LUdecomposition_Simple(rankcheck=True))82def test_QR():83 A = Matrix([[1, 2], [2, 3]])84 Q, S = A.QRdecomposition()85 R = Rational86 assert Q == Matrix([87 [ 5**R(-1, 2), (R(2)/5)*(R(1)/5)**R(-1, 2)],88 [2*5**R(-1, 2), (-R(1)/5)*(R(1)/5)**R(-1, 2)]])89 assert S == Matrix([[5**R(1, 2), 8*5**R(-1, 2)], [0, (R(1)/5)**R(1, 2)]])90 assert Q*S == A91 assert Q.T * Q == eye(2)92 A = Matrix([[1, 1, 1], [1, 1, 3], [2, 3, 4]])93 Q, R = A.QRdecomposition()94 assert Q.T * Q == eye(Q.cols)95 assert R.is_upper96 assert A == Q*R97 A = Matrix([[12, 0, -51], [6, 0, 167], [-4, 0, 24]])98 Q, R = A.QRdecomposition()99 assert Q.T * Q == eye(Q.cols)100 assert R.is_upper101 assert A == Q*R102def test_QR_non_square():103 # Narrow (cols < rows) matrices104 A = Matrix([[9, 0, 26], [12, 0, -7], [0, 4, 4], [0, -3, -3]])105 Q, R = A.QRdecomposition()106 assert Q.T * Q == eye(Q.cols)107 assert R.is_upper108 assert A == Q*R109 A = Matrix([[1, -1, 4], [1, 4, -2], [1, 4, 2], [1, -1, 0]])110 Q, R = A.QRdecomposition()111 assert Q.T * Q == eye(Q.cols)112 assert R.is_upper113 assert A == Q*R114 A = Matrix(2, 1, [1, 2])115 Q, R = A.QRdecomposition()116 assert Q.T * Q == eye(Q.cols)117 assert R.is_upper118 assert A == Q*R119 # Wide (cols > rows) matrices120 A = Matrix([[1, 2, 3], [4, 5, 6]])121 Q, R = A.QRdecomposition()122 assert Q.T * Q == eye(Q.cols)123 assert R.is_upper124 assert A == Q*R125 A = Matrix([[1, 2, 3, 4], [1, 4, 9, 16], [1, 8, 27, 64]])126 Q, R = A.QRdecomposition()127 assert Q.T * Q == eye(Q.cols)128 assert R.is_upper129 assert A == Q*R130 A = Matrix(1, 2, [1, 2])131 Q, R = A.QRdecomposition()132 assert Q.T * Q == eye(Q.cols)133 assert R.is_upper134 assert A == Q*R135def test_QR_trivial():136 # Rank deficient matrices137 A = Matrix([[1, 2, 3], [4, 5, 6], [7, 8, 9]])138 Q, R = A.QRdecomposition()139 assert Q.T * Q == eye(Q.cols)140 assert R.is_upper141 assert A == Q*R142 A = Matrix([[1, 1, 1], [2, 2, 2], [3, 3, 3], [4, 4, 4]])143 Q, R = A.QRdecomposition()144 assert Q.T * Q == eye(Q.cols)145 assert R.is_upper146 assert A == Q*R147 A = Matrix([[1, 1, 1], [2, 2, 2], [3, 3, 3], [4, 4, 4]]).T148 Q, R = A.QRdecomposition()149 assert Q.T * Q == eye(Q.cols)150 assert R.is_upper151 assert A == Q*R152 # Zero rank matrices153 A = Matrix([[0, 0, 0]])154 Q, R = A.QRdecomposition()155 assert Q.T * Q == eye(Q.cols)156 assert R.is_upper157 assert A == Q*R158 A = Matrix([[0, 0, 0]]).T159 Q, R = A.QRdecomposition()160 assert Q.T * Q == eye(Q.cols)161 assert R.is_upper162 assert A == Q*R163 A = Matrix([[0, 0, 0], [0, 0, 0]])164 Q, R = A.QRdecomposition()165 assert Q.T * Q == eye(Q.cols)166 assert R.is_upper167 assert A == Q*R168 A = Matrix([[0, 0, 0], [0, 0, 0]]).T169 Q, R = A.QRdecomposition()170 assert Q.T * Q == eye(Q.cols)171 assert R.is_upper172 assert A == Q*R173 # Rank deficient matrices with zero norm from beginning columns174 A = Matrix([[0, 0, 0], [1, 2, 3]]).T175 Q, R = A.QRdecomposition()176 assert Q.T * Q == eye(Q.cols)177 assert R.is_upper178 assert A == Q*R179 A = Matrix([[0, 0, 0, 0], [1, 2, 3, 4], [0, 0, 0, 0]]).T180 Q, R = A.QRdecomposition()181 assert Q.T * Q == eye(Q.cols)182 assert R.is_upper183 assert A == Q*R184 A = Matrix([[0, 0, 0, 0], [1, 2, 3, 4], [0, 0, 0, 0], [2, 4, 6, 8]]).T185 Q, R = A.QRdecomposition()186 assert Q.T * Q == eye(Q.cols)187 assert R.is_upper188 assert A == Q*R189 A = Matrix([[0, 0, 0], [0, 0, 0], [0, 0, 0], [1, 2, 3]]).T190 Q, R = A.QRdecomposition()191 assert Q.T * Q == eye(Q.cols)192 assert R.is_upper193 assert A == Q*R194def test_QR_float():195 A = Matrix([[1, 1], [1, 1.01]])196 Q, R = A.QRdecomposition()197 assert allclose(Q * R, A)198 assert allclose(Q * Q.T, Matrix.eye(2))199 assert allclose(Q.T * Q, Matrix.eye(2))200 A = Matrix([[1, 1], [1, 1.001]])201 Q, R = A.QRdecomposition()202 assert allclose(Q * R, A)203 assert allclose(Q * Q.T, Matrix.eye(2))204 assert allclose(Q.T * Q, Matrix.eye(2))205def test_LUdecomposition_Simple_iszerofunc():206 # Test if callable passed to matrices.LUdecomposition_Simple() as iszerofunc keyword argument is used inside207 # matrices.LUdecomposition_Simple()208 magic_string = "I got passed in!"209 def goofyiszero(value):210 raise ValueError(magic_string)211 try:212 lu, p = Matrix([[1, 0], [0, 1]]).LUdecomposition_Simple(iszerofunc=goofyiszero)213 except ValueError as err:214 assert magic_string == err.args[0]215 return216 assert False217def test_LUdecomposition_iszerofunc():218 # Test if callable passed to matrices.LUdecomposition() as iszerofunc keyword argument is used inside219 # matrices.LUdecomposition_Simple()220 magic_string = "I got passed in!"221 def goofyiszero(value):222 raise ValueError(magic_string)223 try:224 l, u, p = Matrix([[1, 0], [0, 1]]).LUdecomposition(iszerofunc=goofyiszero)225 except ValueError as err:226 assert magic_string == err.args[0]227 return228 assert False229def test_LDLdecomposition():230 raises(NonSquareMatrixError, lambda: Matrix((1, 2)).LDLdecomposition())231 raises(ValueError, lambda: Matrix(((1, 2), (3, 4))).LDLdecomposition())232 raises(ValueError, lambda: Matrix(((5 + I, 0), (0, 1))).LDLdecomposition())233 raises(ValueError, lambda: Matrix(((1, 5), (5, 1))).LDLdecomposition())234 raises(ValueError, lambda: Matrix(((1, 2), (3, 4))).LDLdecomposition(hermitian=False))235 A = Matrix(((1, 5), (5, 1)))236 L, D = A.LDLdecomposition(hermitian=False)237 assert L * D * L.T == A238 A = Matrix(((25, 15, -5), (15, 18, 0), (-5, 0, 11)))239 L, D = A.LDLdecomposition()240 assert L * D * L.T == A241 assert L.is_lower242 assert L == Matrix([[1, 0, 0], [ Rational(3, 5), 1, 0], [Rational(-1, 5), Rational(1, 3), 1]])243 assert D.is_diagonal()244 assert D == Matrix([[25, 0, 0], [0, 9, 0], [0, 0, 9]])245 A = Matrix(((4, -2*I, 2 + 2*I), (2*I, 2, -1 + I), (2 - 2*I, -1 - I, 11)))246 L, D = A.LDLdecomposition()247 assert expand_mul(L * D * L.H) == A248 assert L.expand() == Matrix([[1, 0, 0], [I/2, 1, 0], [S.Half - I/2, 0, 1]])249 assert D.expand() == Matrix(((4, 0, 0), (0, 1, 0), (0, 0, 9)))250 raises(NonSquareMatrixError, lambda: SparseMatrix((1, 2)).LDLdecomposition())251 raises(ValueError, lambda: SparseMatrix(((1, 2), (3, 4))).LDLdecomposition())252 raises(ValueError, lambda: SparseMatrix(((5 + I, 0), (0, 1))).LDLdecomposition())253 raises(ValueError, lambda: SparseMatrix(((1, 5), (5, 1))).LDLdecomposition())254 raises(ValueError, lambda: SparseMatrix(((1, 2), (3, 4))).LDLdecomposition(hermitian=False))255 A = SparseMatrix(((1, 5), (5, 1)))256 L, D = A.LDLdecomposition(hermitian=False)257 assert L * D * L.T == A258 A = SparseMatrix(((25, 15, -5), (15, 18, 0), (-5, 0, 11)))259 L, D = A.LDLdecomposition()260 assert L * D * L.T == A261 assert L.is_lower262 assert L == Matrix([[1, 0, 0], [ Rational(3, 5), 1, 0], [Rational(-1, 5), Rational(1, 3), 1]])263 assert D.is_diagonal()264 assert D == Matrix([[25, 0, 0], [0, 9, 0], [0, 0, 9]])265 A = SparseMatrix(((4, -2*I, 2 + 2*I), (2*I, 2, -1 + I), (2 - 2*I, -1 - I, 11)))266 L, D = A.LDLdecomposition()267 assert expand_mul(L * D * L.H) == A268 assert L == Matrix(((1, 0, 0), (I/2, 1, 0), (S.Half - I/2, 0, 1)))269 assert D == Matrix(((4, 0, 0), (0, 1, 0), (0, 0, 9)))270def test_pinv_succeeds_with_rank_decomposition_method():271 # Test rank decomposition method of pseudoinverse succeeding272 As = [Matrix([273 [61, 89, 55, 20, 71, 0],274 [62, 96, 85, 85, 16, 0],275 [69, 56, 17, 4, 54, 0],276 [10, 54, 91, 41, 71, 0],277 [ 7, 30, 10, 48, 90, 0],278 [0,0,0,0,0,0]])]279 for A in As:280 A_pinv = A.pinv(method="RD")281 AAp = A * A_pinv282 ApA = A_pinv * A283 assert simplify(AAp * A) == A284 assert simplify(ApA * A_pinv) == A_pinv285 assert AAp.H == AAp286 assert ApA.H == ApA287def test_rank_decomposition():288 a = Matrix(0, 0, [])289 c, f = a.rank_decomposition()290 assert f.is_echelon291 assert c.cols == f.rows == a.rank()292 assert c * f == a293 a = Matrix(1, 1, [5])294 c, f = a.rank_decomposition()295 assert f.is_echelon296 assert c.cols == f.rows == a.rank()297 assert c * f == a298 a = Matrix(3, 3, [1, 2, 3, 1, 2, 3, 1, 2, 3])299 c, f = a.rank_decomposition()300 assert f.is_echelon301 assert c.cols == f.rows == a.rank()302 assert c * f == a303 a = Matrix([304 [0, 0, 1, 2, 2, -5, 3],305 [-1, 5, 2, 2, 1, -7, 5],306 [0, 0, -2, -3, -3, 8, -5],307 [-1, 5, 0, -1, -2, 1, 0]])308 c, f = a.rank_decomposition()309 assert f.is_echelon310 assert c.cols == f.rows == a.rank()...

Full Screen

Full Screen

mac_utils.py

Source:mac_utils.py Github

copy

Full Screen

1mac_chrs = [2 "0", "1", "2", "3", "4", "5", "6", "7", "8", "9",3 "a", "b", "c", "d", "e", "f",4 "A", "B", "C", "D", "E", "F",5]6def get_mac_addr(mac_address, concat_str="-", is_upper=True, part=6):7 """8 获取Mac地址(默认6段式大写)9 """10 mac_address = mac_address.replace("-", "").replace(".", "").replace(":", "").replace(" ", "").strip()11 if len(mac_address) != 12:12 return ""13 if not all([x in mac_chrs for x in mac_address]):14 return ""15 step = 12 // part16 new_mac = concat_str.join([mac_address[x: x + step] for x in range(0, len(mac_address), step)])17 if is_upper:18 return new_mac.upper()19 else:20 return new_mac.lower()21if __name__ == '__main__':22 print("6段式小写:", get_mac_addr("12-34-56-78-90-AB", concat_str=".", is_upper=False, part=6))23 print("6段式大写:", get_mac_addr("12-34-56-78-90-AB", concat_str=".", is_upper=True, part=6))24 print("3段式小写:", get_mac_addr("12-34-56-78-90-AB", concat_str=".", is_upper=False, part=3))25 print("3段式大写:", get_mac_addr("12-34-56-78-90-AB", concat_str=".", is_upper=True, part=3))26 print("6段式小写:", get_mac_addr("1234.5678.90AB", concat_str="-", is_upper=False, part=6))27 print("6段式大写:", get_mac_addr("1234.5678.90AB", concat_str="-", is_upper=True, part=6))28 print("3段式小写:", get_mac_addr("1234.5678.90AB", concat_str="-", is_upper=False, part=3))...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run assertpy automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful