How to use _get_cmd method in autotest

Best Python code snippet using autotest_python Github


Full Screen

...69 getpass.getpass = self._old_getpass70 urllib.request._opener = None71 urllib.request.build_opener = self.old_opener72 super(RegisterTestCase, self).tearDown()73 def _get_cmd(self, metadata=None):74 if metadata is None:75 metadata = {'url': 'xxx', 'author': 'xxx',76 'author_email': 'xxx',77 'name': 'xxx', 'version': 'xxx'}78 pkg_info, dist = self.create_dist(**metadata)79 return register(dist)80 def test_create_pypirc(self):81 # this test makes sure a .pypirc file82 # is created when requested.83 # let's create a register instance84 cmd = self._get_cmd()85 # we shouldn't have a .pypirc file yet86 self.assertFalse(os.path.exists(self.rc))87 # patching input and getpass.getpass88 # so register gets happy89 #90 # Here's what we are faking :91 # use your existing login (choice 1.)92 # Username : 'tarek'93 # Password : 'password'94 # Save your login (y/N)? : 'y'95 inputs = Inputs('1', 'tarek', 'y')96 register_module.input = inputs.__call__97 # let's run the command98 try:99 finally:101 del register_module.input102 # we should have a brand new .pypirc file103 self.assertTrue(os.path.exists(self.rc))104 # with the content similar to WANTED_PYPIRC105 f = open(self.rc)106 try:107 content = self.assertEqual(content, WANTED_PYPIRC)109 finally:110 f.close()111 # now let's make sure the .pypirc file generated112 # really works : we shouldn't be asked anything113 # if we run the command again114 def _no_way(prompt=''):115 raise AssertionError(prompt)116 register_module.input = _no_way117 cmd.show_response = 1118 # let's see what the server received : we should120 # have 2 similar requests121 self.assertEqual(len(self.conn.reqs), 2)122 req1 = dict(self.conn.reqs[0].headers)123 req2 = dict(self.conn.reqs[1].headers)124 self.assertEqual(req1['Content-length'], '1374')125 self.assertEqual(req2['Content-length'], '1374')126 self.assertIn(b'xxx', self.conn.reqs[1].data)127 def test_password_not_in_file(self):128 self.write_file(self.rc, PYPIRC_NOPASSWORD)129 cmd = self._get_cmd()130 cmd._set_config()131 cmd.finalize_options()132 cmd.send_metadata()133 # dist.password should be set134 # therefore used afterwards by other commands135 self.assertEqual(cmd.distribution.password, 'password')136 def test_registering(self):137 # this test runs choice 2138 cmd = self._get_cmd()139 inputs = Inputs('2', 'tarek', '')140 register_module.input = inputs.__call__141 try:142 # let's run the command143 finally:145 del register_module.input146 # we should have send a request147 self.assertEqual(len(self.conn.reqs), 1)148 req = self.conn.reqs[0]149 headers = dict(req.headers)150 self.assertEqual(headers['Content-length'], '608')151 self.assertIn(b'tarek', def test_password_reset(self):153 # this test runs choice 3154 cmd = self._get_cmd()155 inputs = Inputs('3', '')156 register_module.input = inputs.__call__157 try:158 # let's run the command159 finally:161 del register_module.input162 # we should have send a request163 self.assertEqual(len(self.conn.reqs), 1)164 req = self.conn.reqs[0]165 headers = dict(req.headers)166 self.assertEqual(headers['Content-length'], '290')167 self.assertIn(b'tarek', @unittest.skipUnless(docutils is not None, 'needs docutils')169 def test_strict(self):170 # testing the script option171 # when on, the register command stops if172 # the metadata is incomplete or if173 # long_description is not reSt compliant174 # empty metadata175 cmd = self._get_cmd({})176 cmd.ensure_finalized()177 cmd.strict = 1178 self.assertRaises(DistutilsSetupError, # metadata are OK but long_description is broken180 metadata = {'url': 'xxx', 'author': 'xxx',181 'author_email': 'éxéxé',182 'name': 'xxx', 'version': 'xxx',183 'long_description': 'title\n==\n\ntext'}184 cmd = self._get_cmd(metadata)185 cmd.ensure_finalized()186 cmd.strict = 1187 self.assertRaises(DistutilsSetupError, # now something that works189 metadata['long_description'] = 'title\n=====\n\ntext'190 cmd = self._get_cmd(metadata)191 cmd.ensure_finalized()192 cmd.strict = 1193 inputs = Inputs('1', 'tarek', 'y')194 register_module.input = inputs.__call__195 # let's run the command196 try:197 finally:199 del register_module.input200 # strict is not by default201 cmd = self._get_cmd()202 cmd.ensure_finalized()203 inputs = Inputs('1', 'tarek', 'y')204 register_module.input = inputs.__call__205 # let's run the command206 try:207 finally:209 del register_module.input210 # and finally a Unicode test (bug #12114)211 metadata = {'url': 'xxx', 'author': '\u00c9ric',212 'author_email': 'xxx', 'name': 'xxx',213 'version': 'xxx',214 'description': 'Something about esszet \u00df',215 'long_description': 'More things about esszet \u00df'}216 cmd = self._get_cmd(metadata)217 cmd.ensure_finalized()218 cmd.strict = 1219 inputs = Inputs('1', 'tarek', 'y')220 register_module.input = inputs.__call__221 # let's run the command222 try:223 finally:225 del register_module.input226 @unittest.skipUnless(docutils is not None, 'needs docutils')227 def test_register_invalid_long_description(self):228 description = ':funkie:`str`' # mimic Sphinx-specific markup229 metadata = {'url': 'xxx', 'author': 'xxx',230 'author_email': 'xxx',231 'name': 'xxx', 'version': 'xxx',232 'long_description': description}233 cmd = self._get_cmd(metadata)234 cmd.ensure_finalized()235 cmd.strict = True236 inputs = Inputs('2', 'tarek', '')237 register_module.input = inputs238 self.addCleanup(delattr, register_module, 'input')239 self.assertRaises(DistutilsSetupError, def test_check_metadata_deprecated(self):241 # makes sure make_metadata is deprecated242 cmd = self._get_cmd()243 with check_warnings() as w:244 warnings.simplefilter("always")245 cmd.check_metadata()246 self.assertEqual(len(w.warnings), 1)247 def test_list_classifiers(self):248 cmd = self._get_cmd()249 cmd.list_classifiers = 1250 results = self.get_logs(INFO)252 self.assertEqual(results, ['running check', 'xxx'])253 def test_show_response(self):254 # test that the --show-response option return a well formatted response255 cmd = self._get_cmd()256 inputs = Inputs('1', 'tarek', 'y')257 register_module.input = inputs.__call__258 cmd.show_response = 1259 try:260 finally:262 del register_module.input263 results = self.get_logs(INFO)264 self.assertEqual(results[3], 75 * '-' + '\nxxx\n' + 75 * '-')265def test_suite():266 return unittest.makeSuite(RegisterTestCase)267if __name__ == "__main__":...

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:


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?