def test_convert_setup_py_to_cfg_with_description_in_readme(self): self.write_file((self.wdir, 'setup.py'), dedent(""" # coding: utf-8 from distutils.core import setup with open('README.txt') as fp: long_description = fp.read() setup(name='pyxfoil', version='0.2', description='Python bindings for the Xfoil engine', long_description=long_description, maintainer='André Espaze', maintainer_email='*****@*****.**', url='http://www.python-science.org/project/pyxfoil', license='GPLv2', packages=['pyxfoil'], package_data={'pyxfoil': ['fengine.so', 'babar.so']}, data_files=[ ('share/doc/pyxfoil', ['README.rst']), ('share/man', ['pyxfoil.1']), ], ) """), encoding='utf-8') self.write_file((self.wdir, 'README.txt'), dedent(''' My super Death-scription barbar is now in the public domain, ho, baby! ''')) create.input = Inputs('y') main() path = os.path.join(self.wdir, 'setup.cfg') with open(path, encoding='utf-8') as fp: contents = fp.read() self.assertEqual(contents, dedent("""\ [metadata] name = pyxfoil version = 0.2 summary = Python bindings for the Xfoil engine download_url = UNKNOWN home_page = http://www.python-science.org/project/pyxfoil maintainer = André Espaze maintainer_email = [email protected] description-file = README.txt [files] packages = pyxfoil package_data = pyxfoil = fengine.so babar.so resources = README.rst = {doc} pyxfoil.1 = {man} """))
def test_password_reset(self): # this test runs choice 3 cmd = self._get_cmd() inputs = Inputs('3', '*****@*****.**') register_module.input = inputs cmd.ensure_finalized() cmd.run() # we should have send a request self.assertEqual(len(self.conn.reqs), 1) req = self.conn.reqs[0] headers = dict(req.headers) self.assertEqual(headers['Content-length'], '298') self.assertIn(b'tarek', req.data)
def test_create_pypirc(self): # this test makes sure a .pypirc file # is created when requested. # let's create a register instance cmd = self._get_cmd() # we shouldn't have a .pypirc file yet self.assertFalse(os.path.exists(self.rc)) # patching input and getpass.getpass # so register gets happy # Here's what we are faking : # use your existing login (choice 1.) # Username : '******' # Password : '******' # Save your login (y/N)? : 'y' inputs = Inputs('1', 'tarek', 'y') register_module.input = inputs cmd.ensure_finalized() cmd.run() # we should have a brand new .pypirc file self.assertTrue(os.path.exists(self.rc)) # with the content similar to WANTED_PYPIRC with open(self.rc) as fp: content = fp.read() self.assertEqual(content, WANTED_PYPIRC) # now let's make sure the .pypirc file generated # really works : we shouldn't be asked anything # if we run the command again def _no_way(prompt=''): raise AssertionError(prompt) register_module.input = _no_way cmd.show_response = True cmd.finalized = False cmd.ensure_finalized() cmd.run() # let's see what the server received : we should # have 2 similar requests self.assertEqual(len(self.conn.reqs), 2) req1 = dict(self.conn.reqs[0].headers) req2 = dict(self.conn.reqs[1].headers) self.assertEqual(req2['Content-length'], req1['Content-length']) self.assertIn(b'xxx', self.conn.reqs[1].data)
def test_registration(self): # this test runs choice 2 cmd = self._get_cmd() inputs = Inputs('2', 'tarek', '*****@*****.**') register_module.input = inputs # let's run the command # FIXME does this send a real request? use a mock server cmd.ensure_finalized() cmd.run() # we should have send a request self.assertEqual(len(self.conn.reqs), 1) req = self.conn.reqs[0] headers = dict(req.headers) self.assertEqual(headers['Content-length'], '628') self.assertIn(b'tarek', req.data)
def test_register_invalid_long_description(self): description = ':funkie:`str`' # mimic Sphinx-specific markup metadata = { 'Home-page': 'xxx', 'Author': 'xxx', 'Author-email': 'xxx', 'Name': 'xxx', 'Version': 'xxx', 'Description': description } cmd = self._get_cmd(metadata) cmd.ensure_finalized() cmd.strict = True inputs = Inputs('2', 'tarek', '*****@*****.**') register_module.input = inputs with self.assertRaises(PackagingSetupError) as e: cmd.run() self.assertIn('funkie', str(e.exception))
def test_strict(self): # testing the strict option: when on, the register command stops if the # metadata is incomplete or if description contains bad reST # empty metadata # XXX this is not really empty.. cmd = self._get_cmd({'name': 'xxx', 'version': 'xxx'}) cmd.ensure_finalized() cmd.strict = True inputs = Inputs('1', 'tarek', 'y') register_module.input = inputs self.assertRaises(PackagingSetupError, cmd.run) # metadata is OK but description is broken metadata = { 'home_page': 'xxx', 'author': 'xxx', 'author_email': 'éxéxé', 'name': 'xxx', 'version': '4.2', 'description': 'title\n==\n\ntext' } cmd = self._get_cmd(metadata) cmd.ensure_finalized() cmd.strict = True self.assertRaises(PackagingSetupError, cmd.run) # now something that works metadata['description'] = 'title\n=====\n\ntext' cmd = self._get_cmd(metadata) cmd.ensure_finalized() cmd.strict = True inputs = Inputs('1', 'tarek', 'y') register_module.input = inputs cmd.ensure_finalized() cmd.run() # strict is not by default cmd = self._get_cmd() cmd.ensure_finalized() inputs = Inputs('1', 'tarek', 'y') register_module.input = inputs cmd.ensure_finalized() cmd.run() # and finally a Unicode test (bug #12114) metadata = { 'home_page': 'xxx', 'author': '\u00c9ric', 'author_email': 'xxx', 'name': 'xxx', 'version': 'xxx', 'summary': 'Something about esszet \u00df', 'description': 'More things about esszet \u00df' } cmd = self._get_cmd(metadata) cmd.ensure_finalized() cmd.strict = True inputs = Inputs('1', 'tarek', 'y') register_module.input = inputs cmd.ensure_finalized() cmd.run()
def test_convert_setup_py_to_cfg(self): self.write_file((self.wdir, 'setup.py'), dedent(""" # coding: utf-8 from distutils.core import setup long_description = '''My super Death-scription barbar is now on the public domain, ho, baby !''' setup(name='pyxfoil', version='0.2', description='Python bindings for the Xfoil engine', long_description=long_description, maintainer='André Espaze', maintainer_email='*****@*****.**', url='http://www.python-science.org/project/pyxfoil', license='GPLv2', packages=['pyxfoil', 'babar', 'me'], data_files=[ ('share/doc/pyxfoil', ['README.rst']), ('share/man', ['pyxfoil.1']), ], py_modules=['my_lib', 'mymodule'], package_dir={ 'babar': '', 'me': 'Martinique/Lamentin', }, package_data={ 'babar': ['Pom', 'Flora', 'Alexander'], 'me': ['dady', 'mumy', 'sys', 'bro'], 'pyxfoil': ['fengine.so'], }, scripts=['my_script', 'bin/run'], ) """), encoding='utf-8') create.input = Inputs('y') main() path = os.path.join(self.wdir, 'setup.cfg') with open(path, encoding='utf-8') as fp: contents = fp.read() self.assertEqual(contents, dedent("""\ [metadata] name = pyxfoil version = 0.2 summary = Python bindings for the Xfoil engine download_url = UNKNOWN home_page = http://www.python-science.org/project/pyxfoil maintainer = André Espaze maintainer_email = [email protected] description = My super Death-scription |barbar is now on the public domain, |ho, baby ! [files] packages = pyxfoil babar me modules = my_lib mymodule scripts = my_script bin/run package_data = babar = Pom Flora Alexander me = dady mumy sys bro pyxfoil = fengine.so resources = README.rst = {doc} pyxfoil.1 = {man} """))
def test_set_multi(self): mainprogram = MainProgram() create.input = Inputs('aaaaa') mainprogram.data['author'] = [] mainprogram._set_multi('_set_multi test', 'author') self.assertEqual(['aaaaa'], mainprogram.data['author'])
def test_ask(self): create.input = Inputs('a', 'b') self.assertEqual('a', ask('is this a test')) self.assertEqual('b', ask(str(list(range(0, 70))), default='c', lengthy=True))
def test_ask_yn(self): create.input = Inputs('y') self.assertEqual('y', ask_yn('is this a test'))