Best Python code snippet using autotest_python
generateTestCases.py
Source: generateTestCases.py
1# New Generate Test Cases 2import numpy as np 3import math 4import os,sys5from testCase import get_testCase6# import copy 7# from keras.callbacks import History 8# import tensorflow as tf9sys.path.append('../')10sys.path.append('../../')11from grader_support import stdout_redirector12from grader_support import util13os.environ['TF_CPP_MIN_LOG_LEVEL']='3'14# This grader is for the Emojify assignment15mFiles = [16 "one_step_attention.py",17 "model.py"18]19class suppress_stdout_stderr(object):20 '''21 A context manager for doing a "deep suppression" of stdout and stderr in 22 Python, i.e. will suppress all print, even if the print originates in a 23 compiled C/Fortran sub-function.24 This will not suppress raised exceptions, since exceptions are printed25 to stderr just before a script exits, and after the context manager has26 exited (at least, I think that is why it lets exceptions through). 27 '''28 def __init__(self):29 # Open a pair of null files30 self.null_fds = [os.open(os.devnull,os.O_RDWR) for x in range(2)]31 # Save the actual stdout (1) and stderr (2) file descriptors.32 self.save_fds = [os.dup(1), os.dup(2)]33 def __enter__(self):34 # Assign the null pointers to stdout and stderr.35 os.dup2(self.null_fds[0],1)36 os.dup2(self.null_fds[1],2)37 def __exit__(self, *_):38 # Re-assign the real stdout/stderr back to (1) and (2)39 os.dup2(self.save_fds[0],1)40 os.dup2(self.save_fds[1],2)41 # Close all file descriptors42 for fd in self.null_fds + self.save_fds:43 os.close(fd)44np.random.seed(3)45with suppress_stdout_stderr():46 from solutions import *47 from testCase import get_testCase48 n_a = 6449 n_s = 12850 m = 1051 dataset, human_vocab, machine_vocab, inv_machine_vocab = load_dataset(m)52 human_vocab_size = len(human_vocab)53 machine_vocab_size = len(machine_vocab)54 im = model(Tx, Ty, n_a, n_s, human_vocab_size, machine_vocab_size)55 cp1 = im.count_params()56 mi1 = len(im.inputs)57 mo1 = len(im.outputs)58 ml1 = len(im.layers)59 m_out1 = np.asarray((cp1, mi1, mo1, ml1))60 # GRADED FUNCTION: one_step_attention61 m_out2 = get_testCase()62def generateTestCases():63 testCases = {64 'one_step_attention': {65 'partId': 'zcQIs',66 'testCases': [67 {68 'testInput': 0,69 'testOutput': m_out270 }71 ]72 },73 'model': { 74 'partId': 'PTKef',75 'testCases': [76 {77 'testInput': (Tx, Ty, n_a, n_s, human_vocab_size, machine_vocab_size),78 'testOutput': m_out179 }80 ]81 }82 }...
auto_test.py
Source: auto_test.py
...4import os5import sys6import re7import unittest8def get_testcase(py_file):9 with open(py_file, 'r') as file:10 s = file.read()11 pattern = r'\bclass (\w+TestCase)\('12 return re.findall(pattern, s)13if __name__ == "__main__":14 import_templet_ = r'from TestSuite.%s import %s'15 addTest_templet_ = r'suite.addTests(unittest.TestLoader().loadTestsFromTestCase(%s))'16 suite = unittest.TestSuite()17 ut_path = os.path.split(os.path.realpath(__file__))[0]18 # all19 testsuite_path = os.path.join(ut_path, 'TestSuite')20 if len(sys.argv) == 1:21 for file in os.listdir(testsuite_path):22 file_path = os.path.join(testsuite_path, file)23 case_list = get_testcase(file_path)24 for case in case_list:25 import_ = import_templet_ % (file[:-3], case)26 exec import_27 addTest_ = addTest_templet_ % case28 exec addTest_29 # sys.argv30 else:31 for file in sys.argv[1:]:32 if not file.endswith('.py'):33 file += '.py'34 if not file.startswith('test_'):35 file = 'test_' + file36 file_path = os.path.join(testsuite_path, file)37 case_list = get_testcase(file_path)38 for case in case_list:39 import_ = import_templet_ % (file[:-3], case)40 exec import_41 addTest_ = addTest_templet_ % case42 exec addTest_ 43 runner = unittest.TextTestRunner() ...
run_test.py
Source: run_test.py
1#!/usr/bin/env python2# -*- coding: utf-8 -*-3import unittest, pytest4from unittest import defaultTestLoader5import os6def get_TestCase():7 discover = unittest.defaultTestLoader.discover(os.getcwd(), pattern="test*.py")8 # print(discover)9 suite = unittest.TestSuite()10 suite.addTest(discover)11 return suite12if __name__ == '__main__':13 # get_TestCase()14 # runner = unittest.TextTestRunner(verbosity=3)15 # runner.run(get_TestCase())...
Check out the latest blogs from LambdaTest on this topic:
Before we discuss Scala testing, let us understand the fundamentals of Scala and how this programming language is a preferred choice for your development requirements.The popularity and usage of Scala are rapidly rising, evident by the ever-increasing open positions for Scala developers.
So, now that the first installment of this two fold article has been published (hence you might have an idea of what Agile Testing is not in my opinion), I’ve started feeling the pressure to explain what Agile Testing actually means to me.
Did you know that according to Statista, the number of smartphone users will reach 18.22 billion by 2025? Let’s face it, digital transformation is skyrocketing and will continue to do so. This swamps the mobile app development market with various options and gives rise to the need for the best mobile app testing tools
As a developer, checking the cross browser compatibility of your CSS properties is of utmost importance when building your website. I have often found myself excited to use a CSS feature only to discover that it’s still not supported on all browsers. Even if it is supported, the feature might be experimental and not work consistently across all browsers. Ask any front-end developer about using a CSS feature whose support is still in the experimental phase in most prominent web browsers. ????
The count of mobile users is on a steep rise. According to the research, by 2025, it is expected to reach 7.49 billion users worldwide. 70% of all US digital media time comes from mobile apps, and to your surprise, the average smartphone owner uses ten apps per day and 30 apps each month.
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!