How to use test_dashes_are_allowed_in_key_names method in autotest

Best Python code snippet using autotest_python

base_utils_unittest.py

Source:base_utils_unittest.py Github

copy

Full Screen

...165 self.assertRaises(ValueError, self.read_keyval, "a$=one\n")166 def test_underscores_are_allowed_in_key_names(self):167 keyval = self.read_keyval("a_b=value\n")168 self.assertEquals(keyval, {"a_b": "value"})169 def test_dashes_are_allowed_in_key_names(self):170 keyval = self.read_keyval("a-b=value\n")171 self.assertEquals(keyval, {"a-b": "value"})172 def test_empty_value_is_allowed(self):173 keyval = self.read_keyval("a=\n")174 self.assertEquals(keyval, {"a": ""})175class test_write_keyval(unittest.TestCase):176 def setUp(self):177 self.god = mock.mock_god(ut=self)178 self.god.stub_function(base_utils, "open")179 self.god.stub_function(os.path, "isdir")180 def tearDown(self):181 self.god.unstub_all()182 def assertHasLines(self, value, lines):183 vlines = value.splitlines()184 vlines.sort()185 self.assertEquals(vlines, sorted(lines))186 def write_keyval(self, filename, dictionary, expected_filename=None,187 type_tag=None):188 if expected_filename is None:189 expected_filename = filename190 test_file = StringIO.StringIO()191 self.god.stub_function(test_file, "close")192 base_utils.open.expect_call(expected_filename, "a").and_return(test_file)193 test_file.close.expect_call()194 if type_tag is None: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):...

Full Screen

Full Screen

utils_unittest.py

Source:utils_unittest.py Github

copy

Full Screen

...155 self.assertRaises(ValueError, self.read_keyval, "a$=one\n")156 def test_underscores_are_allowed_in_key_names(self):157 keyval = self.read_keyval("a_b=value\n")158 self.assertEquals(keyval, {"a_b": "value"})159 def test_dashes_are_allowed_in_key_names(self):160 keyval = self.read_keyval("a-b=value\n")161 self.assertEquals(keyval, {"a-b": "value"})162class test_write_keyval(unittest.TestCase):163 def setUp(self):164 self.god = mock.mock_god()165 self.god.stub_function(utils, "open")166 self.god.stub_function(os.path, "isdir")167 def tearDown(self):168 self.god.unstub_all()169 def assertHasLines(self, value, lines):170 vlines = value.splitlines()171 vlines.sort()172 self.assertEquals(vlines, sorted(lines))173 def write_keyval(self, filename, dictionary, expected_filename=None,174 type_tag=None):175 if expected_filename is None:176 expected_filename = filename177 test_file = StringIO.StringIO()178 self.god.stub_function(test_file, "close")179 utils.open.expect_call(expected_filename, "a").and_return(test_file)180 test_file.close.expect_call()181 if type_tag is None: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):...

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