Best Python code snippet using tempest_python
test_unstable.py
Source: test_unstable.py
1#!/usr/bin/env python2import os3import shutil4import tempfile5from test.utils import MOCK_DIR, PYTHON_INSTALL_PATH, \6 MAKE_CMD, succeed, assert_exists, create_catkin_workspace7from . import network_test_utils8from network_test_utils import AbstractUnstableTest9class SimpleUnstableTest(AbstractUnstableTest):10 def __init__(self, testCaseName):11 super(SimpleUnstableTest, self).__init__(testCaseName, 'unstable_test')12 def setUp(self):13 super(SimpleUnstableTest, self).setUp()14 # a bit dirty here, tester needs to manually delete15 # test/tmp/unstable_test/build folder. But else, tests take16 # too long17 if not os.path.exists(os.path.join(self.builddir, "Makefile")):18 self.cmake()19 # if make fails due to DistributionNotFound,20 # tester needs to manually delete test/tmp/unstable_test/src21 succeed(MAKE_CMD, cwd=self.builddir)22 succeed(MAKE_CMD + ["install"], cwd=self.builddir)23 def test_make(self):24 # uses core ros stacks installed in setUp25 # just checks the result for success26 self.assertTrue(os.path.exists(self.workspacedir))27 assert_exists(self.builddir,28 'ros')29 assert_exists(self.develspace,30 'bin',31 'etc',32 'include',33 'lib',34 'share')35 assert_exists(self.installdir,36 'bin',37 'etc',38 'include',39 'lib',40 'share')41 def test_common_msgs_against_installed(self):42 # uses core ros stacks installed in setUp43 # tries to build common_msgs in separate workspace44 try:45 # create another workspace than self.rootdir46 other_root_dir = tempfile.mkdtemp()47 other_src_dir = os.path.join(other_root_dir, 'src')48 create_catkin_workspace(other_src_dir)49 other_build_dir = os.path.join(other_root_dir, 'build')50 other_develspace_dir = os.path.join(other_build_dir, 'devel')51 shutil.copytree(os.path.join(self.workspacedir, 'common_msgs'),52 os.path.join(other_src_dir, 'common_msgs'))53 out = self.cmake(cwd=other_build_dir,54 srcdir=other_src_dir)55 out = succeed(MAKE_CMD, cwd=other_build_dir)56 assert_exists(other_develspace_dir,57 PYTHON_INSTALL_PATH + '/nav_msgs/msg/_GridCells.py',58 'include/nav_msgs/GridCells.h')59 out = succeed(MAKE_CMD + ['install'], cwd=other_build_dir)60 assert_exists(self.installdir,61 'include/geometry_msgs/PointStamped.h',62 PYTHON_INSTALL_PATH + '/geometry_msgs/msg/_PointStamped.py',63 'share/geometry_msgs/msg/PointStamped.msg',64 # 'share/typelibxml/geometry_msgs/PointStamped.xml',65 )66 finally:67 # pass68 shutil.rmtree(other_root_dir)69 def test_mock_against_installed(self):70 # uses core ros stacks installed in setUp71 # tries to build mock project in separate workspace72 try:73 # create another workspace than self.rootdir74 other_root_dir = tempfile.mkdtemp()75 other_src_dir = os.path.join(other_root_dir, 'src')76 create_catkin_workspace(other_src_dir)77 other_build_dir = os.path.join(other_root_dir, 'build')78 other_develspace_dir = os.path.join(other_build_dir, 'devel')79 other_install_dir = os.path.join(other_root_dir, 'install')80 shutil.copytree(os.path.join(MOCK_DIR, 'src', 'catkin_test'),81 os.path.join(other_src_dir, 'catkin_test'))82 self.cmake(cwd=other_build_dir,83 srcdir=other_src_dir,84 installdir=other_install_dir)85 succeed(MAKE_CMD, cwd=other_build_dir)86 assert_exists(other_develspace_dir,87 "lib/liba.so",88 "lib/libb.so",89 "lib/libc-one.so",90 "lib/libc-two.so",91 "lib/libd.so")92 assert_exists(other_build_dir,93 # "bin/nolangs_exec",94 "catkin_test/quux_user/bin/quux_srv-exec")95 assert_exists(other_develspace_dir,96 PYTHON_INSTALL_PATH + "/a",97 # PYTHON_INSTALL_PATH + "/b",98 # PYTHON_INSTALL_PATH + "/c",99 # PYTHON_INSTALL_PATH + "/d",100 PYTHON_INSTALL_PATH + "/a/__init__.py",101 PYTHON_INSTALL_PATH + "/quux_msgs/__init__.py")102 # "DESTDIR="103 succeed(MAKE_CMD + ["install"],104 cwd=other_build_dir)105 assert_exists(other_install_dir,106 "lib/pkgconfig/a.pc",107 "lib/pkgconfig/b.pc",108 "lib/pkgconfig/c.pc",109 "lib/pkgconfig/d.pc",110 "lib/pkgconfig/quux_msgs.pc",111 PYTHON_INSTALL_PATH + "/a/__init__.py",112 PYTHON_INSTALL_PATH + "/quux_msgs/__init__.py")113 #114 # make sure python imports work115 #116 # succeed([other_build_dir + "/env.sh", "python -c 'import a'"])117 # succeed([other_build_dir + "/env.sh", "python -c 'import b'"])118 finally:119 # pass...
test.py
Source: test.py
1from inference.optimizer import load_weights2from utils.util import (load_data, get_stability_classes, 3 convert_to_array, plot_cutoff)4from inference.optimizer import metric_object5from inference.inference import KLdivergence6from utils.preprocess import preprocess_data7import time8if __name__ == "__main__":9 filename = "data/Electrical Grid Stability.csv"10 egrid_data = load_data(filename)11 stable_class, unstable_class = get_stability_classes(egrid_data)12 stable_grid = convert_to_array(stable_class)13 _, stable_val, stable_test = preprocess_data(14 stable_grid)15 unstable_grid = convert_to_array(unstable_class)16 _, _, unstable_test = preprocess_data(17 unstable_grid)18 LOSS = metric_object19 original_dim = 13 20 model = load_weights(original_dim)21 model_output, _ = KLdivergence(model, LOSS, stable_val)22 stable_output, _ = KLdivergence(model, LOSS, stable_test)23 unstable_output, _ = KLdivergence(model, LOSS, unstable_test)...
Check out the latest blogs from LambdaTest on this topic:
These days, development teams depend heavily on feedback from automated tests to evaluate the quality of the system they are working on.
I think that probably most development teams describe themselves as being “agile” and probably most development teams have standups, and meetings called retrospectives.There is also a lot of discussion about “agile”, much written about “agile”, and there are many presentations about “agile”. A question that is often asked is what comes after “agile”? Many testers work in “agile” teams so this question matters to us.
I routinely come across test strategy documents when working with customers. They are lengthy—100 pages or more—and packed with monotonous text that is routinely reused from one project to another. Yawn once more— the test halt and resume circumstances, the defect management procedure, entrance and exit criteria, unnecessary generic risks, and in fact, one often-used model replicates the requirements of textbook testing, from stress to systems integration.
To understand the agile testing mindset, we first need to determine what makes a team “agile.” To me, an agile team continually focuses on becoming self-organized and cross-functional to be able to complete any challenge they may face during a project.
When working on web automation with Selenium, I encountered scenarios where I needed to refresh pages from time to time. When does this happen? One scenario is that I needed to refresh the page to check that the data I expected to see was still available even after refreshing. Another possibility is to clear form data without going through each input individually.
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!!