How to use test_ints method in assertpy

Best Python code snippet using assertpy_python

test_foo_primitives.py

Source:test_foo_primitives.py Github

copy

Full Screen

1# -*- coding: utf-8 -*-2from __future__ import absolute_import, division, print_function, unicode_literals3import pytest4# Example code written by a python developer to access cpp implementation of Foo5# This file should be hand-written by a python developer6from foo_primitives import FooPrimitives7from djinni.support import decoded_utf_88import datetime9import sys10PYTHON3 = sys.version_info[0] >= 311from PyCFFIlib_cffi import lib12# testing climits: http://www.cplusplus.com/reference/climits/13def test_int8():14 foo = FooPrimitives.create()15 min_i8 = -12816 foo.set_int8(min_i8)17 assert min_i8 == foo.get_int8(), "test_ints failed"18 max_i8 = 12719 foo.set_int8(max_i8)20 assert max_i8 == foo.get_int8(), "test_ints failed"21 pytest.raises(OverflowError, foo.set_int8, min_i8 - 1)22 pytest.raises(OverflowError, foo.set_int8, max_i8 + 1)23# testing climits: http://www.cplusplus.com/reference/climits/24def test_int16():25 foo = FooPrimitives.create()26 min_i16 = -3276827 foo.set_int16(min_i16)28 assert min_i16 == foo.get_int16(), "test_ints failed"29 max_i16 = 3276730 foo.set_int16(max_i16)31 assert max_i16 == foo.get_int16(), "test_ints failed"32 pytest.raises(OverflowError, foo.set_int16, min_i16 - 1)33 pytest.raises(OverflowError, foo.set_int16, max_i16 + 1)34def test_int32():35 foo = FooPrimitives.create()36 min_i32 = -214748364837 foo.set_int32(min_i32)38 assert min_i32 == foo.get_int32(), "test_ints failed"39 max_i32 = 214748364740 foo.set_int32(max_i32)41 assert max_i32 == foo.get_int32(), "test_ints failed"42 pytest.raises(OverflowError, foo.set_int32, min_i32 - 1)43 pytest.raises(OverflowError, foo.set_int32, max_i32 + 1)44def test_int64():45 foo = FooPrimitives.create()46 min_i64 = -922337203685477580847 foo.set_int64(min_i64)48 assert min_i64 == foo.get_int64(), "test_ints failed"49 max_i64 = 922337203685477580750 foo.set_int64(max_i64)51 assert max_i64 == foo.get_int64(), "test_ints failed"52 pytest.raises(OverflowError, foo.set_int64, min_i64 - 1)53 pytest.raises(OverflowError, foo.set_int64, max_i64 + 1)54def test_float():55 foo = FooPrimitives.create()56 min_f32 = lib.min_f32_t()57 foo.set_float(min_f32)58 assert min_f32 == foo.get_float(), "test_float failed"59 max_f32 = lib.max_f32_t()60 foo.set_float(max_f32)61 assert max_f32 == foo.get_float(), "test_float failed"62def test_double():63 foo = FooPrimitives.create()64 min_f64 = lib.min_f64_t()65 foo.set_double(min_f64)66 assert min_f64 == foo.get_double(), "test_double failed"67 max_f64 = lib.max_f64_t()68 foo.set_double(max_f64)69 assert max_f64 == foo.get_double(), "test_double failed"70def test_binary():71 foo = FooPrimitives.create()72 b = b''73 foo.set_binary(b)74 bGet = foo.get_binary()75 assert b == bGet, "test_binary failed"76 assert type(bGet) is bytes77 b = b'123g'78 foo.set_binary(b)79 bGet = foo.get_binary()80 assert b == bGet, "test_binary failed"81 assert type(bGet) is bytes82def test_bool():83 foo = FooPrimitives.create()84 b = True85 foo.set_bool(b)86 assert b == foo.get_bool(), "test_bool failed"87 b = False88 foo.set_bool(b)89 assert b == foo.get_bool(), "test_bool failed"90def test_date():91 epoch = datetime.datetime.utcfromtimestamp(0)92 foo = FooPrimitives.create()93 d = datetime.datetime(2007,4,17,1,2,3)94 foo.set_date(d)95 assert d == foo.get_date(), "test_date failed"96 for i in range(100): # more reliable97 d = datetime.datetime.now()98 d = d.replace(microsecond = (d.microsecond // 1000) * 1000) # our precision is millisecond level99 foo.set_date(d)100 assert d == foo.get_date(), "test_date failed"101# Can set: unicode strings (python 2 and 3), bytes utf-8 encoded (python 3)102# Will get: utf-8 encoded strings, and utf-8 encoded bytes respectively103DECODEUtf8 = 1104def test_strings():105 foo = FooPrimitives.create()106 strs = dict([107 # PYTHON 2 and 3 unicode strings108 (u"", not DECODEUtf8),109 (u"my\0text", not DECODEUtf8),110 (u"the best text", not DECODEUtf8),111 (u"my \b friend", not DECODEUtf8),112 #"Non-ASCII /\0 非 ASCII 字符"113 (u"Non-ASCII /\0 \xe9\x9d\x9e ASCII \xe5\xad\x97\xe7\xac\xa6", not DECODEUtf8),114 (u"Non-ASCII /\0 \u975e ASCII \u5b57\u7b26", not DECODEUtf8)115 ])116 if PYTHON3:117 strs.update({118 chr(40960) + u'abcd' + chr(1972) + u"\0\bhi": not DECODEUtf8, #unicode string119 bytes(chr(40960) + u'abcd' + chr(1972) + u"\0\bhi", 'utf-8'): DECODEUtf8 # bytes utf-8 encoded120 })121 else:122 strs.update({123 unichr(40960) + u'abcd' + unichr(1972) + u"\0\bhi": not DECODEUtf8, #unicode string for python 2124 })125 for sSet, decode in strs.items():126 foo.set_string(sSet)127 sSetUnicode = sSet128 if decode:129 sSetUnicode = decoded_utf_8(sSet)130 sGetUnicode = foo.get_string()131 # print ("client SetPrs=", sSetUnicode, ".", len(sSetUnicode), List(sSetUnicode) )132 # print ("client GetPrs=", sGetUnicode, ".", len(sGetUnicode), List(sGetUnicode))...

Full Screen

Full Screen

test_multi.py

Source:test_multi.py Github

copy

Full Screen

1from __future__ import absolute_import2from __future__ import division3from __future__ import print_function4import argparse5from functools import partial6import json7import traceback8import imlib as im9import numpy as np10import pylib11import tensorflow as tf12import tflib as tl13import data14import models15# ==============================================================================16# = param =17# ==============================================================================18parser = argparse.ArgumentParser()19parser.add_argument('--experiment_name', dest='experiment_name', help='experiment_name')20parser.add_argument('--test_atts', dest='test_atts', nargs='+', help='test_atts')21parser.add_argument('--test_ints', dest='test_ints', type=float, nargs='+', help='test_ints')22args_ = parser.parse_args()23with open('./output/%s/setting.txt' % args_.experiment_name) as f:24 args = json.load(f)25# model26atts = args['atts']27n_att = len(atts)28img_size = args['img_size']29shortcut_layers = args['shortcut_layers']30inject_layers = args['inject_layers']31enc_dim = args['enc_dim']32dec_dim = args['dec_dim']33dis_dim = args['dis_dim']34dis_fc_dim = args['dis_fc_dim']35enc_layers = args['enc_layers']36dec_layers = args['dec_layers']37dis_layers = args['dis_layers']38# testing39test_atts = args_.test_atts40thres_int = args['thres_int']41test_ints = args_.test_ints42# others43use_cropped_img = args['use_cropped_img']44experiment_name = args_.experiment_name45assert test_atts is not None, 'test_atts should be chosen in %s' % (str(atts))46for a in test_atts:47 assert a in atts, 'test_atts should be chosen in %s' % (str(atts))48assert len(test_ints) == len(test_atts), 'the lengths of test_ints and test_atts should be the same!'49# ==============================================================================50# = graphs =51# ==============================================================================52# data53sess = tl.session()54te_data = data.Celeba('./data', atts, img_size, 1, part='test', sess=sess, crop=not use_cropped_img)55# models56Genc = partial(models.Genc, dim=enc_dim, n_layers=enc_layers)57Gdec = partial(models.Gdec, dim=dec_dim, n_layers=dec_layers, shortcut_layers=shortcut_layers, inject_layers=inject_layers)58# inputs59xa_sample = tf.placeholder(tf.float32, shape=[None, img_size, img_size, 3])60_b_sample = tf.placeholder(tf.float32, shape=[None, n_att])61# sample62x_sample = Gdec(Genc(xa_sample, is_training=False), _b_sample, is_training=False)63# ==============================================================================64# = test =65# ==============================================================================66# initialization67ckpt_dir = './output/%s/checkpoints' % experiment_name68try:69 tl.load_checkpoint(ckpt_dir, sess)70except:71 raise Exception(' [*] No checkpoint!')72# sample73try:74 for idx, batch in enumerate(te_data):75 xa_sample_ipt = batch[0]76 a_sample_ipt = batch[1]77 b_sample_ipt = np.array(a_sample_ipt, copy=True)78 for a in test_atts:79 i = atts.index(a)80 b_sample_ipt[:, i] = 1 - b_sample_ipt[:, i] # inverse attribute81 b_sample_ipt = data.Celeba.check_attribute_conflict(b_sample_ipt, atts[i], atts)82 x_sample_opt_list = [xa_sample_ipt, np.full((1, img_size, img_size // 10, 3), -1.0)]83 _b_sample_ipt = (b_sample_ipt * 2 - 1) * thres_int84 for a, i in zip(test_atts, test_ints):85 _b_sample_ipt[..., atts.index(a)] = _b_sample_ipt[..., atts.index(a)] * i / thres_int86 x_sample_opt_list.append(sess.run(x_sample, feed_dict={xa_sample: xa_sample_ipt, _b_sample: _b_sample_ipt}))87 sample = np.concatenate(x_sample_opt_list, 2)88 save_dir = './output/%s/sample_testing_multi_%s' % (experiment_name, str(test_atts))89 pylib.mkdir(save_dir)90 im.imwrite(sample.squeeze(0), '%s/%d.png' % (save_dir, idx + 182638))91 print('%d.png done!' % (idx + 182638))92except:93 traceback.print_exc()94finally:...

Full Screen

Full Screen

script.py

Source:script.py Github

copy

Full Screen

1# use extract_test_cases script to generate test cases2# redirect output of above script to a file test_cases.txt3# function uses only one input, an integer4import sys5import os6test_cases = open("testcases.txt","r")7all_cases = test_cases.readlines()8test_ints = {}9count = 110for x in all_cases:11 test_ints[count] = [y.strip() for y in x.split()]12 count = count + 113student = sys.argv[1]14score = 015for x in test_ints:16 golden_command = "python3 golden.py " + " ".join(test_ints[x])17 student_command = "python3 " + str(student) + " " + " ".join(test_ints[x])18 golden_out = os.popen(golden_command).read()19 student_out = os.popen(student_command).read()20 if golden_out == student_out:21 score = score + 1...

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