Best Python code snippet using autotest_python
base_utils_unittest.py
Source:base_utils_unittest.py
...195 base_utils.write_keyval(filename, dictionary)196 else:197 base_utils.write_keyval(filename, dictionary, type_tag)198 return test_file.getvalue()199 def write_keyval_file(self, dictionary, type_tag=None):200 os.path.isdir.expect_call("file").and_return(False)201 return self.write_keyval("file", dictionary, type_tag=type_tag)202 def test_accesses_files_directly(self):203 os.path.isdir.expect_call("file").and_return(False)204 result = self.write_keyval("file", {"a": "1"})205 self.assertEquals(result, "a=1\n")206 def test_accesses_directories_through_keyval_file(self):207 os.path.isdir.expect_call("dir").and_return(True)208 result = self.write_keyval("dir", {"b": "2"}, "dir/keyval")209 self.assertEquals(result, "b=2\n")210 def test_numbers_are_stringified(self):211 result = self.write_keyval_file({"c": 3})212 self.assertEquals(result, "c=3\n")213 def test_type_tags_are_excluded_by_default(self):214 result = self.write_keyval_file({"d": "a string"})215 self.assertEquals(result, "d=a string\n")216 self.assertRaises(ValueError, self.write_keyval_file,217 {"d{perf}": "a string"})218 def test_perf_tags_are_allowed(self):219 result = self.write_keyval_file({"a{perf}": 1, "b{perf}": 2},220 type_tag="perf")221 self.assertHasLines(result, ["a{perf}=1", "b{perf}=2"])222 self.assertRaises(ValueError, self.write_keyval_file,223 {"a": 1, "b": 2}, type_tag="perf")224 def test_non_alphanumeric_keynames_are_rejected(self):225 self.assertRaises(ValueError, self.write_keyval_file, {"x$": 0})226 def test_underscores_are_allowed_in_key_names(self):227 result = self.write_keyval_file({"a_b": "value"})228 self.assertEquals(result, "a_b=value\n")229 def test_dashes_are_allowed_in_key_names(self):230 result = self.write_keyval_file({"a-b": "value"})231 self.assertEquals(result, "a-b=value\n")232class test_is_url(unittest.TestCase):233 def test_accepts_http(self):234 self.assertTrue(base_utils.is_url("http://example.com"))235 def test_accepts_ftp(self):236 self.assertTrue(base_utils.is_url("ftp://ftp.example.com"))237 def test_rejects_local_path(self):238 self.assertFalse(base_utils.is_url("/home/username/file"))239 def test_rejects_local_filename(self):240 self.assertFalse(base_utils.is_url("filename"))241 def test_rejects_relative_local_path(self):242 self.assertFalse(base_utils.is_url("somedir/somesubdir/file"))243 def test_rejects_local_path_containing_url(self):244 self.assertFalse(base_utils.is_url("somedir/http://path/file"))...
utils_unittest.py
Source:utils_unittest.py
...182 utils.write_keyval(filename, dictionary)183 else:184 utils.write_keyval(filename, dictionary, type_tag)185 return test_file.getvalue()186 def write_keyval_file(self, dictionary, type_tag=None):187 os.path.isdir.expect_call("file").and_return(False)188 return self.write_keyval("file", dictionary, type_tag=type_tag)189 def test_accesses_files_directly(self):190 os.path.isdir.expect_call("file").and_return(False)191 result = self.write_keyval("file", {"a": "1"})192 self.assertEquals(result, "a=1\n")193 def test_accesses_directories_through_keyval_file(self):194 os.path.isdir.expect_call("dir").and_return(True)195 result = self.write_keyval("dir", {"b": "2"}, "dir/keyval")196 self.assertEquals(result, "b=2\n")197 def test_numbers_are_stringified(self):198 result = self.write_keyval_file({"c": 3})199 self.assertEquals(result, "c=3\n")200 def test_type_tags_are_excluded_by_default(self):201 result = self.write_keyval_file({"d": "a string"})202 self.assertEquals(result, "d=a string\n")203 self.assertRaises(ValueError, self.write_keyval_file,204 {"d{perf}": "a string"})205 def test_perf_tags_are_allowed(self):206 result = self.write_keyval_file({"a{perf}": 1, "b{perf}": 2},207 type_tag="perf")208 self.assertHasLines(result, ["a{perf}=1", "b{perf}=2"])209 self.assertRaises(ValueError, self.write_keyval_file,210 {"a": 1, "b": 2}, type_tag="perf")211 def test_non_alphanumeric_keynames_are_rejected(self):212 self.assertRaises(ValueError, self.write_keyval_file, {"x$": 0})213 def test_underscores_are_allowed_in_key_names(self):214 result = self.write_keyval_file({"a_b": "value"})215 self.assertEquals(result, "a_b=value\n")216 def test_dashes_are_allowed_in_key_names(self):217 result = self.write_keyval_file({"a-b": "value"})218 self.assertEquals(result, "a-b=value\n")219class test_is_url(unittest.TestCase):220 def test_accepts_http(self):221 self.assertTrue(utils.is_url("http://example.com"))222 def test_accepts_ftp(self):223 self.assertTrue(utils.is_url("ftp://ftp.example.com"))224 def test_rejects_local_path(self):225 self.assertFalse(utils.is_url("/home/username/file"))226 def test_rejects_local_filename(self):227 self.assertFalse(utils.is_url("filename"))228 def test_rejects_relative_local_path(self):229 self.assertFalse(utils.is_url("somedir/somesubdir/file"))230 def test_rejects_local_path_containing_url(self):231 self.assertFalse(utils.is_url("somedir/http://path/file"))...
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!!