How to use test_input_values method in lettuce_webdriver

Best Python code snippet using lettuce_webdriver_python

test_model.py

Source:test_model.py Github

copy

Full Screen

1import pandas as pd2import pytest3from src.recsys.model import mean_center, normalize, softmax4def test_mean_center():5 test_input_values = [6 0.0,7 0.0,8 0.0,9 247.0,10 4.0,11 0.0,12 0.0,13 0.0,14 0.0,15 0.0,16 0.0,17 5.0,18 0.0,19 0.0,20 0.0,21 0.0,22 0.0,23 0.0,24 2.0,25 6.0,26 264.0,27 ]28 test_input_index = pd.Index(29 [30 "brazilian",31 "british",32 "cajun_creole",33 "chinese",34 "filipino",35 "french",36 "greek",37 "indian",38 "irish",39 "italian",40 "jamaican",41 "japanese",42 "korean",43 "mexican",44 "moroccan",45 "russian",46 "southern_us",47 "spanish",48 "thai",49 "vietnamese",50 "ingr_sum",51 ],52 name="cuisine",53 )54 test_input = pd.Series(test_input_values, index=test_input_index)55 test = mean_center(test_input)56 true_values = [57 -13.2,58 -13.2,59 -13.2,60 233.8,61 -9.2,62 -13.2,63 -13.2,64 -13.2,65 -13.2,66 -13.2,67 -13.2,68 -8.2,69 -13.2,70 -13.2,71 -13.2,72 -13.2,73 -13.2,74 -13.2,75 -11.2,76 -7.2,77 264.0,78 ]79 true_index = pd.Index(80 data=[81 "brazilian",82 "british",83 "cajun_creole",84 "chinese",85 "filipino",86 "french",87 "greek",88 "indian",89 "irish",90 "italian",91 "jamaican",92 "japanese",93 "korean",94 "mexican",95 "moroccan",96 "russian",97 "southern_us",98 "spanish",99 "thai",100 "vietnamese",101 "ingr_sum",102 ],103 name="cuisine",104 )105 true = pd.Series(true_values, index=true_index)106 pd.testing.assert_series_equal(test, true)107def test_mean_center_empty():108 test_input = pd.Series([], dtype="object")109 with pytest.raises(ValueError):110 mean_center(test_input)111def test_normalize():112 test_input_values = [0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 3.0, 0.0, 0.0]113 test_input_index = pd.Index(114 [115 "Gochujang base",116 "Italian bread",117 "Italian parsley leaves",118 "Mexican cheese blend",119 "Mexican oregano",120 "Shaoxing wine",121 "Sriracha",122 "Tabasco Pepper Sauce",123 "Thai fish sauce",124 "Thai red curry paste",125 ],126 name="ingredient",127 )128 test_input = pd.Series(test_input_values, index=test_input_index)129 test = normalize(test_input)130 true_values = [-0.1, -0.1, 0.15, -0.1, -0.1, -0.1, -0.1, 0.65, -0.1, -0.1]131 true_index = pd.Index(132 [133 "Gochujang base",134 "Italian bread",135 "Italian parsley leaves",136 "Mexican cheese blend",137 "Mexican oregano",138 "Shaoxing wine",139 "Sriracha",140 "Tabasco Pepper Sauce",141 "Thai fish sauce",142 "Thai red curry paste",143 ],144 name="ingredient",145 )146 true = pd.Series(true_values, index=true_index)147 pd.testing.assert_series_equal(test, true)148def test_normalize_empty():149 test = normalize(pd.Series([], dtype="object"))150 true = pd.Series([], dtype="object")151 pd.testing.assert_series_equal(test, true)152def test_softmax():153 test_input_values = [154 0.0,155 0.0,156 0.0,157 247.0,158 4.0,159 0.0,160 0.0,161 0.0,162 0.0,163 0.0,164 0.0,165 5.0,166 0.0,167 0.0,168 0.0,169 0.0,170 0.0,171 0.0,172 2.0,173 6.0,174 264.0,175 ]176 test_input_index = pd.Index(177 [178 "brazilian",179 "british",180 "cajun_creole",181 "chinese",182 "filipino",183 "french",184 "greek",185 "indian",186 "irish",187 "italian",188 "jamaican",189 "japanese",190 "korean",191 "mexican",192 "moroccan",193 "russian",194 "southern_us",195 "spanish",196 "thai",197 "vietnamese",198 "ingr_sum",199 ],200 name="cuisine",201 )202 test_input = pd.Series(test_input_values, index=test_input_index)203 test = softmax(test_input).astype("str")204 true_values = [205 "2.2195082290865866e-115",206 "2.2195082290865866e-115",207 "2.2195082290865866e-115",208 "4.1399375473943345e-08",209 "1.2118104329146771e-113",210 "2.2195082290865866e-115",211 "2.2195082290865866e-115",212 "2.2195082290865866e-115",213 "2.2195082290865866e-115",214 "2.2195082290865866e-115",215 "2.2195082290865866e-115",216 "3.294042279329056e-113",217 "2.2195082290865866e-115",218 "2.2195082290865866e-115",219 "2.2195082290865866e-115",220 "2.2195082290865866e-115",221 "2.2195082290865866e-115",222 "2.2195082290865866e-115",223 "1.6400070816759008e-114",224 "8.954135270075986e-113",225 "0.9999999586006246",226 ]227 true_index = pd.Index(228 [229 "brazilian",230 "british",231 "cajun_creole",232 "chinese",233 "filipino",234 "french",235 "greek",236 "indian",237 "irish",238 "italian",239 "jamaican",240 "japanese",241 "korean",242 "mexican",243 "moroccan",244 "russian",245 "southern_us",246 "spanish",247 "thai",248 "vietnamese",249 "ingr_sum",250 ],251 name="cuisine",252 )253 true = pd.Series(true_values, true_index)254 pd.testing.assert_series_equal(test, true)255def test_softmax_empty():256 test = softmax(pd.Series([], dtype="object"))257 true = pd.Series([], dtype="object")...

Full Screen

Full Screen

wide_deep_test.py

Source:wide_deep_test.py Github

copy

Full Screen

1from __future__ import absolute_import2from __future__ import division3from __future__ import print_function4import os5import tensorflow as tf6import sys7PACKAGE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))8sys.path.insert(0, PACKAGE_DIR)9from lib.read_conf import Config10from lib.dataset import input_fn11from lib.build_estimator import build_estimator12TEST_CSV = os.path.join(os.path.dirname(PACKAGE_DIR), 'data/test/test2')13USED_FEATURE_KEY = Config().get_feature_name('used')14def _read_test_input():15 for line in open(TEST_CSV):16 return line17TEST_INPUT_VALUES = _read_test_input()18TEST_INPUT_KEYS = Config().get_feature_name()19TEST_INPUT = zip(TEST_INPUT_KEYS, TEST_INPUT_VALUES)20class BaseTest(tf.test.TestCase):21 def setUp(self):22 # Create temporary CSV file23 self.temp_dir = self.get_temp_dir()24 self.input_csv = os.path.join(self.temp_dir, 'test.csv')25 with tf.gfile.Open(self.input_csv, 'w') as temp_csv:26 temp_csv.write(TEST_INPUT_VALUES)27 def test_input_fn(self):28 features, labels = input_fn(self.input_csv, 'eval', batch_size=1)29 with tf.Session() as sess:30 features, labels = sess.run((features, labels))31 # Compare the two features dictionaries.32 for key in USED_FEATURE_KEY:33 self.assertTrue(key in features)34 self.assertEqual(len(features[key]), 1)35 feature_value = features[key][0]36 # Convert from bytes to string for Python 3.37 if isinstance(feature_value, bytes):38 feature_value = feature_value.decode()39 self.assertEqual(TEST_INPUT[key], feature_value)40 self.assertFalse(labels)41 def build_and_test_estimator(self, model_type):42 """Ensure that model trains and minimizes loss."""43 model = build_estimator(self.temp_dir, model_type)44 # Train for 1 step to initialize model and evaluate initial loss45 model.train(46 input_fn=lambda: input_fn(47 TEST_CSV, None, 'eval', batch_size=1),48 steps=1)49 initial_results = model.evaluate(50 input_fn=lambda: input_fn(51 TEST_CSV, None, 'eval', batch_size=1))52 # Train for 100 epochs at batch size 3 and evaluate final loss53 model.train(54 input_fn=lambda: input_fn(55 TEST_CSV, None, 'eval', batch_size=8))56 final_results = model.evaluate(57 input_fn=lambda: input_fn(58 TEST_CSV, None, 'eval', batch_size=1))59 print('%s initial results:' % model_type, initial_results)60 print('%s final results:' % model_type, final_results)61 # Ensure loss has decreased, while accuracy and both AUCs have increased.62 self.assertLess(final_results['loss'], initial_results['loss'])63 self.assertGreater(final_results['auc'], initial_results['auc'])64 self.assertGreater(final_results['auc_precision_recall'],65 initial_results['auc_precision_recall'])66 self.assertGreater(final_results['accuracy'], initial_results['accuracy'])67 def test_wide_deep_estimator_training(self):68 self.build_and_test_estimator('wide_deep')69if __name__ == '__main__':70 tf.logging.set_verbosity(tf.logging.ERROR)...

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