How to use test_a_file method in tavern

Best Python code snippet using tavern

test_output.py

Source:test_output.py Github

copy

Full Screen

1from ast import FunctionDef2from os import path3from munch import munchify4from pyfakefs.pytest_plugin import fs5import pytest6from pytestgen.load import PyTestGenInputFile7from pytestgen.parse import PyTestGenParsedSet, PyTestGenParsedFile, get_existing_test_functions8import pytestgen.output9from fixtures import mock_module_testable_func, mock_class_testable_func10@pytest.fixture11def mock_parsed_file(mock_module_testable_func, mock_class_testable_func):12 return PyTestGenParsedFile(13 [mock_module_testable_func(),14 mock_class_testable_func()], PyTestGenInputFile("a_file.py", "a_dir"))15@pytest.fixture16def mock_parsed_set(mock_parsed_file):17 fake_input_set = munchify({"output_dir": "output"})18 return PyTestGenParsedSet([mock_parsed_file], fake_input_set)19def test_output_tests(fs, mock_parsed_set, monkeypatch):20 pytestgen.output.output_tests(mock_parsed_set)21 test_file_path = path.join("output", "a_dir", "test_a_file.py")22 assert path.exists(test_file_path) == True, "test file did not exist"23 # we need to patch FunctionDef back in, it was patched out in the24 # 'mock_class_testable_func' fixture used in 'mock_parsed_set'25 # otherwise isinstance() for FunctionDef will fail in26 # get_existing_test_functions()27 monkeypatch.setattr(pytestgen.parse.ast, "FunctionDef", FunctionDef)28 outputted_funcs = get_existing_test_functions(test_file_path)29 assert outputted_funcs == [30 "test_a_test_function", "test_testclass_a_class_test_function"31 ]32def test_output_tests_include(fs, mock_parsed_set, monkeypatch):33 pytestgen.output.output_tests(mock_parsed_set, include=["a_test_function"])34 test_file_path = path.join("output", "a_dir", "test_a_file.py")35 assert path.exists(test_file_path) == True, "test file did not exist"36 # we need to patch FunctionDef back in, it was patched out in the37 # 'mock_class_testable_func' fixture used in 'mock_parsed_set'38 # otherwise isinstance() for FunctionDef will fail in39 # get_existing_test_functions()40 monkeypatch.setattr(pytestgen.parse.ast, "FunctionDef", FunctionDef)41 outputted_funcs = get_existing_test_functions(test_file_path)42 assert outputted_funcs == ["test_a_test_function"]43def test_output_parsed_file_nonexist(fs, mock_parsed_file, monkeypatch):44 test_file_path = path.join("output", "a_dir", "test_a_file.py")45 pytestgen.output._output_parsed_file(mock_parsed_file, "output")46 assert path.exists(test_file_path) == True, "test file did not exist"47 # we need to patch FunctionDef back in, it was patched out in the48 # 'mock_class_testable_func' fixture used in 'mock_parsed_set'49 # otherwise isinstance() for FunctionDef will fail in50 # get_existing_test_functions()51 monkeypatch.setattr(pytestgen.parse.ast, "FunctionDef", FunctionDef)52 outputted_funcs = get_existing_test_functions(test_file_path)53 assert outputted_funcs == [54 "test_a_test_function", "test_testclass_a_class_test_function"55 ]56def test_output_parsed_file_exists(fs, mock_parsed_file, monkeypatch):57 test_file_path = path.join("output", "a_dir", "test_a_file.py")58 fs.create_file(mock_parsed_file.input_file.get_test_file_path("output"))59 pytestgen.output._output_parsed_file(mock_parsed_file, "output")60 assert path.exists(test_file_path) == True, "test file did not exist"61 # we need to patch FunctionDef back in, it was patched out in the62 # 'mock_class_testable_func' fixture used in 'mock_parsed_set'63 # otherwise isinstance() for FunctionDef will fail in64 # get_existing_test_functions()65 monkeypatch.setattr(pytestgen.parse.ast, "FunctionDef", FunctionDef)66 outputted_funcs = get_existing_test_functions(test_file_path)67 assert outputted_funcs == [68 "test_a_test_function", "test_testclass_a_class_test_function"69 ]70def test_ensure_dir_non_exist(fs):71 pytestgen.output._ensure_dir(path.join("test_dir", "test_name.py"))72 assert path.exists("test_dir") == True73def test_ensure_dir_exist(fs):74 fs.create_dir("test_dir")75 pytestgen.output._ensure_dir(path.join("test_dir", "test_name.py"))...

Full Screen

Full Screen

TestUnorderedCSV.py

Source:TestUnorderedCSV.py Github

copy

Full Screen

...33 localResults['fail'] += 134 print('FAILED '+comment)35 print(localMsg)36 print('')37def test_a_file(fname):38 """39 Tests the file40 @ In, fname, string, filename string41 @ Out, test_a_file, (same, message), (bool, str) result of test.42 """43 differ = UCSV('.', [fname], zeroThreshold=5e-14)44 differ.diff()45 return differ.__dict__['_UnorderedCSVDiffer__same'],\46 differ.__dict__['_UnorderedCSVDiffer__message']47if __name__ == '__main__':48 results = {'pass':0, 'fail':0}49 # passes50 ok, msg = test_a_file('okay.csv')51 check_same('Okay', ok, True, msg, results)52 # mismatch53 ok, msg = test_a_file('mismatch.csv')54 check_same('Mismatch', ok, False, msg, results)55 # matching with inf, nan56 ok, msg = test_a_file('inf.csv')57 check_same('Infinity', ok, True, msg, results)58 # zero threshold59 ok, msg = test_a_file('nearzero.csv')60 check_same('Near zero', ok, True, msg, results)61 # sorting62 ok, msg = test_a_file('sort.csv')63 check_same('sort', ok, True, msg, results)64 print('Passed:', results['pass'], '| Failed:', results['fail'])...

Full Screen

Full Screen

05_02_cyclegan_monet.py

Source:05_02_cyclegan_monet.py Github

copy

Full Screen

1#!/usr/bin/env python2# coding: utf-83import os4import matplotlib.pyplot as plt5from models.cycleGAN import CycleGAN6from utils.loaders import DataLoader7# run params8SECTION = 'paint'9RUN_ID = '0001'10DATA_NAME = 'airplane2line'11RUN_FOLDER = 'run/{}/'.format(SECTION)12RUN_FOLDER += '_'.join([RUN_ID, DATA_NAME])13if not os.path.exists(RUN_FOLDER):14 os.mkdir(RUN_FOLDER)15 os.mkdir(os.path.join(RUN_FOLDER, 'viz'))16 os.mkdir(os.path.join(RUN_FOLDER, 'images'))17 os.mkdir(os.path.join(RUN_FOLDER, 'weights'))18mode = 'build' # 'build' # 19IMAGE_SIZE = 25620data_loader = DataLoader(dataset_name=DATA_NAME, img_res=(IMAGE_SIZE, IMAGE_SIZE))21# ## 모델 생성22gan = CycleGAN(23 input_dim = (IMAGE_SIZE,IMAGE_SIZE,3)24 , learning_rate = 0.000125 , lambda_validation = 126 , lambda_reconstr = 1027 , lambda_id = 528 , generator_type = 'resnet'29 , gen_n_filters = 64 #원래 32였음30 , disc_n_filters = 6431 )32if mode == 'build':33 gan.save(RUN_FOLDER)34else:35 gan.load_weights(os.path.join(RUN_FOLDER, 'weights/weights.h5'))36gan.g_BA.summary()37gan.g_AB.summary()38gan.d_A.summary()39gan.d_B.summary()40# ## 모델 훈련41BATCH_SIZE = 142EPOCHS = 1043PRINT_EVERY_N_BATCHES = 1044TEST_A_FILE = '0143381.jpg'45TEST_B_FILE = 'n02691156_10391-6.png'46gan.train(data_loader47 , run_folder = RUN_FOLDER48 , epochs=EPOCHS49 , test_A_file = TEST_A_FILE50 , test_B_file = TEST_B_FILE51 , batch_size=BATCH_SIZE...

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