Best Python code snippet using autotest_python
test_fs.py
Source: test_fs.py
...19from tripleo.utils.fs import Dir, File20class TestDir(TestCase):21 """Tests for :class:`Dir`.22 """23 def test_check_exists(self):24 """Check that an error is thrown if the directory does not exist.25 """26 directory = Dir('some/made/up/path')27 with self.assertRaises(IOError):28 directory.check_exists()29 def test_exists(self):30 """Checks that this tells that the path points to a folder which31 exists.32 """33 with TemporaryDirectory() as path:34 directory = Dir(path)35 self.assertTrue(directory.exists())36 def test_not_exists(self):37 """Checks that it can tell if the directory exists.38 """39 directory = Dir('some/made/up/path')40 self.assertFalse(directory.exists())41 def test_not_directory(self):42 """Checks that it can tell if a path is not a directory.43 """44 with NamedTemporaryFile() as buffer:45 directory = Dir(buffer.name)46 self.assertFalse(directory.exists())47 def test_dir_is_empty(self):48 """Checks that this can tell whether the directory has files in it49 or not.50 """51 with TemporaryDirectory() as folder:52 directory = Dir(folder)53 self.assertTrue(directory.is_empty())54 with NamedTemporaryFile(dir=directory):55 self.assertFalse(directory.is_empty())56 def test_cd(self):57 """Checks that a path to a subdirectory is created as expected.58 """59 subfolder = 'folder'60 with TemporaryDirectory() as folder:61 directory = Dir(folder)62 self.assertEqual(63 f'{directory}/{subfolder}',64 directory.cd(subfolder)65 )66 def test_mkdir_error(self):67 """Checks that an error is raised if the directory's parents do not68 exist.69 """70 directory = Dir('path/to/some/dir')71 with self.assertRaises(FileNotFoundError):72 directory.mkdir(recursive=False)73 def test_simple_mkdir(self):74 """Checks that a folder can be created under a parent directory.75 """76 with TemporaryDirectory() as folder:77 directory = Dir(f'{folder}/dir')78 self.assertFalse(directory.exists())79 directory.mkdir(recursive=False)80 self.assertTrue(directory.exists())81 def test_recursive_mkdir(self):82 """Checks that all the folders leading to a directory can be83 created.84 """85 with TemporaryDirectory() as folder:86 directory = Dir(f'{folder}/dir/subdir')87 self.assertFalse(directory.exists())88 directory.mkdir(recursive=True)89 self.assertTrue(directory.exists())90 @skip(reason='Will fail on CI')91 def test_rm(self):92 """Checks that it is possible to delete the folder and everything93 inside.94 """95 with TemporaryDirectory() as folder:96 directory = Dir(folder)97 self.assertTrue(directory.exists())98 directory.rm()99 self.assertFalse(directory.exists())100 def test_as_path(self):101 """Checks that the type can be converted into a path.102 """103 path = Path('path/to/dir')104 directory = Dir(path)105 self.assertEqual(path, directory.as_path())106 def test_str(self):107 """Checks that the type can be converted into a string through __str__.108 """109 path = 'path/to/dir'110 directory = Dir(path)111 self.assertEqual(path, str(directory))112class TestFile(TestCase):113 """Tests for :class:`File`.114 """115 def test_check_exists(self):116 """Checks that an error is thrown if the file does not exist.117 """118 file = File('some/path/to/a/file')119 with self.assertRaises(IOError):120 file.check_exists()121 def test_exists(self):122 """Checks that this is able to tell whether a file exists on the123 filesystem or not.124 """125 with NamedTemporaryFile() as buffer:126 file = File(buffer.name)127 self.assertTrue(file.exists())128 def test_not_file(self):129 """Checks that it can tell if a path is a file or not....
test_config.py
Source: test_config.py
1import os2import pytest3import bugtracker4def test_check_exists():5 """6 Check if the config file exists.7 """8 config_path = "../apps/bugtracker.json"9 assert os.path.isfile(config_path)10def test_fields():11 """12 Check all fields exist.13 Check that all folders exist.14 """15 config_path = "../apps/bugtracker.json"16 config = bugtracker.config.load(config_path)17 folders = ["plot_dir", "netcdf_dir", "cache_dir", "animation_dir"]18 for folder in folders:...
run_test.py
Source: run_test.py
1from tests import test_plot, test_emoji2# test_plot.test_plot()3test_emoji.test_check_exists()...
Check out the latest blogs from LambdaTest on this topic:
One of the most important skills for leaders to have is the ability to prioritize. To understand how we can organize all of the tasks that must be completed in order to complete a project, we must first understand the business we are in, particularly the project goals. There might be several project drivers that stimulate project execution and motivate a company to allocate the appropriate funding.
Ever since the Internet was invented, web developers have searched for the most efficient ways to display content on web browsers.
Mobile devices and mobile applications – both are booming in the world today. The idea of having the power of a computer in your pocket is revolutionary. As per Statista, mobile accounts for more than half of the web traffic worldwide. Mobile devices (excluding tablets) contributed to 54.4 percent of global website traffic in the fourth quarter of 2021, increasing consistently over the past couple of years.
Smartphones have changed the way humans interact with technology. Be it travel, fitness, lifestyle, video games, or even services, it’s all just a few touches away (quite literally so). We only need to look at the growing throngs of smartphone or tablet users vs. desktop users to grasp this reality.
There is just one area where each member of the software testing community has a distinct point of view! Metrics! This contentious issue sparks intense disputes, and most conversations finish with no definitive conclusion. It covers a wide range of topics: How can testing efforts be measured? What is the most effective technique to assess effectiveness? Which of the many components should be quantified? How can we measure the quality of our testing performance, among other things?
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!!