How to use test_foo_bar method in Testify

Best Python code snippet using Testify_python

test_restorer.py

Source:test_restorer.py Github

copy

Full Screen

1from typing import List, Tuple, Union2from pydantic import BaseModel3from pytest import mark4from pydantic_settings import TextLocation5from pydantic_settings.decoder.json import decode_document6from pydantic_settings.restorer import (7 ModelShapeRestorer,8 _build_model_flat_map,9)10from .conftest import Model1, Model4, Model5, Model611class YAModel(BaseModel):12 list: List[str]13class WithComplexTypes(BaseModel):14 list: List[str] # will be ignored because not supported15 tuple: Tuple[str]16 union: Union[str, int, bool] # path pointer end here17 models_union: Union[Model1, YAModel] # will expand nested path18 # expand first model, but still allow this point19 model_union_with_simple: Union[Model1, int]20def test_with_complex_types():21 assert {22 key: tuple(val)23 for key, val in _build_model_flat_map(24 WithComplexTypes, 't', str.casefold25 ).items()26 } == {27 't_list': (('list',), False, False),28 't_tuple': (('tuple',), False, False),29 't_union': (('union',), False, False),30 't_models_union': (('models_union',), True, True),31 't_models_union_foo': (('models_union', 'foo'), False, False),32 't_models_union_bar': (('models_union', 'bar'), False, False),33 't_models_union_list': (('models_union', 'list'), False, False),34 't_model_union_with_simple': (35 ('model_union_with_simple',),36 True,37 False,38 ),39 't_model_union_with_simple_foo': (40 ('model_union_with_simple', 'foo'),41 False,42 False,43 ),44 't_model_union_with_simple_bar': (45 ('model_union_with_simple', 'bar'),46 False,47 False,48 ),49 }50def test_flat_model():51 assert _build_model_flat_map(Model1, 'test', str.casefold) == {52 'test_foo': (('foo',), False, False),53 'test_bar': (('bar',), False, False),54 }55@mark.parametrize('model_cls', [Model4, Model5])56def test_complex_nested_models(model_cls):57 assert _build_model_flat_map(model_cls, 'test', str.casefold) == {58 'test_foo': (('foo',), True, True),59 'test_foo_bar': (('foo', 'bar'), False, False),60 'test_foo_baz': (('foo', 'baz'), False, False),61 }62@mark.parametrize(63 'model_cls, input_val, result, locations',64 [65 (66 Model1,67 {'test_foo': 'VAL1', 'test_bar': 'VAL2'},68 {'foo': 'VAL1', 'bar': 'VAL2'},69 {('foo',): ('test_foo', None), ('bar',): ('test_bar', None)},70 ),71 (72 Model4,73 {'test_foo': '{"bar": "VAL1", "baz": "VAL2"}'},74 {'foo': {'bar': 'VAL1', 'baz': 'VAL2'}},75 {76 ('foo', 'bar'): (77 'test_foo',78 TextLocation(79 line=1,80 col=9,81 end_line=1,82 end_col=15,83 pos=9,84 end_pos=14,85 ),86 ),87 ('foo', 'baz'): (88 'test_foo',89 TextLocation(90 line=1,91 col=24,92 end_line=1,93 end_col=30,94 pos=24,95 end_pos=29,96 ),97 ),98 },99 ),100 (101 Model4,102 {'test_foo_bar': 'VAL1', 'test_foo_baz': 'VAL2'},103 {'foo': {'bar': 'VAL1', 'baz': 'VAL2'}},104 {105 ('foo', 'bar'): ('test_foo_bar', None),106 ('foo', 'baz'): ('test_foo_baz', None),107 },108 ),109 (110 Model4,111 {'test_foo_bar': 'VAL1'},112 {'foo': {'bar': 'VAL1'}},113 {('foo', 'bar'): ('test_foo_bar', None)},114 ),115 (116 Model6,117 {'test_baz_bam_foo': 'VAL1', 'test_baz_bam_bar': 'VAL2'},118 {'baz': {'bam': {'foo': 'VAL1', 'bar': 'VAL2'}}},119 {120 ('baz', 'bam', 'foo'): ('test_baz_bam_foo', None),121 ('baz', 'bam', 'bar'): ('test_baz_bam_bar', None),122 },123 ),124 (125 Model6,126 {'test_baz_bam': '{"foo": "VAL1", "bar": "VAL2"}'},127 {'baz': {'bam': {'foo': 'VAL1', 'bar': 'VAL2'}}},128 {129 ('baz', 'bam', 'foo'): (130 'test_baz_bam',131 TextLocation(132 line=1,133 col=9,134 end_line=1,135 end_col=15,136 pos=9,137 end_pos=14,138 ),139 ),140 ('baz', 'bam', 'bar'): (141 'test_baz_bam',142 TextLocation(143 line=1,144 col=24,145 end_line=1,146 end_col=30,147 pos=24,148 end_pos=29,149 ),150 ),151 },152 ),153 (154 Model6,155 {'test_baz': '{"bam": {"foo": "VAL1", "bar": "VAL2"}}'},156 {'baz': {'bam': {'foo': 'VAL1', 'bar': 'VAL2'}}},157 {158 ('baz', 'bam', 'foo'): (159 'test_baz',160 TextLocation(161 line=1,162 col=17,163 end_line=1,164 end_col=23,165 pos=17,166 end_pos=22,167 ),168 )169 },170 ),171 (172 Model6,173 {174 'test_baz_bam_foo': 'VAL1',175 'test_baz_bam_bar': 'VAL2',176 'test_baf_foo': 'VAL3',177 },178 {179 'baz': {'bam': {'foo': 'VAL1', 'bar': 'VAL2'}},180 'baf': {'foo': 'VAL3'},181 },182 {183 ('baz', 'bam', 'foo'): ('test_baz_bam_foo', None),184 ('baz', 'bam', 'bar'): ('test_baz_bam_bar', None),185 ('baf', 'foo'): ('test_baf_foo', None),186 },187 ),188 ],189)190def test_restore_model(model_cls, input_val, result, locations):191 values, errs = ModelShapeRestorer(192 model_cls, 'TEST', False, decode_document193 ).restore(input_val)194 assert values, errs == (result, [])...

Full Screen

Full Screen

test_runner.py

Source:test_runner.py Github

copy

Full Screen

1#!/usr/bin/env python2# -*- coding: utf-8 -*-3# Copyright (c) 2012-2021 SoftBank Robotics. All rights reserved.4# Use of this source code is governed by a BSD-style license (see the COPYING file).5""" Test Runner """6from __future__ import absolute_import7from __future__ import unicode_literals8from __future__ import print_function9import pytest10import qitest.runner11import qitest.project12class DummyTestRunner(qitest.runner.TestSuiteRunner):13 """ DummyTestRunner """14 def launcher(self):15 """ Launcher """16 pass17def test_match_patterns(tmpdir):18 """ Test Match Patterns """19 test_foo = {"name": "test_foo"}20 test_bar = {"name": "test_bar"}21 test_foo_bar = {"name": "test_foo_bar"}22 test_spam = {"name": "test_spam"}23 nightly = {"name": "nightly", "nightly": True}24 perf = {"name": "perf", "perf": True}25 tests = [test_foo, test_bar, test_foo_bar, test_spam, nightly, perf]26 qitest_json = tmpdir.ensure("qitest.json", file=True)27 qitest.conf.write_tests(tests, qitest_json.strpath)28 test_project = qitest.project.TestProject(qitest_json.strpath)29 test_runner = DummyTestRunner(test_project)30 test_runner.patterns = ["foo"]31 assert test_runner.tests == [test_foo, test_foo_bar]32 test_runner.patterns = ["foo", "bar"]33 assert test_runner.tests == [test_foo, test_bar, test_foo_bar]34 with pytest.raises(Exception):35 test_runner.patterns = "foo("36 test_runner.patterns = list()37 assert test_runner.tests == [test_foo, test_bar, test_foo_bar, test_spam]38 test_runner.nightly = True39 test_runner.perf = False40 assert test_runner.tests == [41 test_foo, test_bar, test_foo_bar, test_spam, nightly]42 test_runner.perf = True43 test_runner.nightly = False44 assert test_runner.tests == [perf]45def test_exclude(tmpdir):46 """ Test Exclude """47 test_foo = {"name": "test_foo"}48 test_bar = {"name": "test_bar"}49 test_foo_bar = {"name": "test_foo_bar"}50 tests = [test_foo, test_bar, test_foo_bar]51 qitest_json = tmpdir.ensure("qitest.json", file=True)52 qitest.conf.write_tests(tests, qitest_json.strpath)53 test_project = qitest.project.TestProject(qitest_json.strpath)54 test_runner = DummyTestRunner(test_project)55 test_runner.excludes = ["foo"]...

Full Screen

Full Screen

test_addpath.py

Source:test_addpath.py Github

copy

Full Screen

1import fs2import pytest3import sys4from .setup import *5def test_addpath():6 TEST_MODULE = 'test_foo_bar.py'7 fs.touch(fs.join(TEST_DIR, TEST_MODULE))8 with pytest.raises(ImportError):9 import test_foo_bar10 fs.addpath(TEST_DIR)11 import test_foo_bar12 sys.path.remove(TEST_DIR)13 del sys.modules['test_foo_bar']14def test_addpath_not_existing_path():15 WRONG_TEST_DIR = 'foobartest'16 with pytest.raises(ValueError):...

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 Testify 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