| 
									
										
										
										
											2011-05-19 13:07:25 +02:00
										 |  |  | """Tests for packaging.run.""" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import os | 
					
						
							|  |  |  | import sys | 
					
						
							| 
									
										
										
										
											2011-05-31 12:09:34 +02:00
										 |  |  | from io import StringIO | 
					
						
							| 
									
										
										
										
											2011-05-19 13:07:25 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-31 12:09:34 +02:00
										 |  |  | from packaging import install | 
					
						
							| 
									
										
										
										
											2011-09-18 20:11:48 +02:00
										 |  |  | from packaging.tests import unittest, support | 
					
						
							| 
									
										
										
										
											2011-05-31 12:09:34 +02:00
										 |  |  | from packaging.run import main | 
					
						
							| 
									
										
										
										
											2011-05-19 13:07:25 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-09-10 05:18:20 +02:00
										 |  |  | from test.script_helper import assert_python_ok | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-19 13:07:25 +02:00
										 |  |  | # setup script that uses __file__ | 
					
						
							|  |  |  | setup_using___file__ = """\
 | 
					
						
							|  |  |  | __file__ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | from packaging.run import setup | 
					
						
							|  |  |  | setup() | 
					
						
							|  |  |  | """
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | setup_prints_cwd = """\
 | 
					
						
							|  |  |  | import os | 
					
						
							|  |  |  | print os.getcwd() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | from packaging.run import setup | 
					
						
							|  |  |  | setup() | 
					
						
							|  |  |  | """
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-09-10 05:18:20 +02:00
										 |  |  | class RunTestCase(support.TempdirManager, | 
					
						
							|  |  |  |                   support.LoggingCatcher, | 
					
						
							|  |  |  |                   unittest.TestCase): | 
					
						
							| 
									
										
										
										
											2011-05-19 13:07:25 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     def setUp(self): | 
					
						
							| 
									
										
										
										
											2011-09-10 05:18:20 +02:00
										 |  |  |         super(RunTestCase, self).setUp() | 
					
						
							| 
									
										
										
										
											2011-05-19 13:07:25 +02:00
										 |  |  |         self.old_argv = sys.argv, sys.argv[:] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def tearDown(self): | 
					
						
							|  |  |  |         sys.argv = self.old_argv[0] | 
					
						
							|  |  |  |         sys.argv[:] = self.old_argv[1] | 
					
						
							| 
									
										
										
										
											2011-09-10 05:18:20 +02:00
										 |  |  |         super(RunTestCase, self).tearDown() | 
					
						
							| 
									
										
										
										
											2011-05-19 13:07:25 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     # TODO restore the tests removed six months ago and port them to pysetup | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-31 12:09:34 +02:00
										 |  |  |     def test_install(self): | 
					
						
							|  |  |  |         # making sure install returns 0 or 1 exit codes | 
					
						
							|  |  |  |         project = os.path.join(os.path.dirname(__file__), 'package.tgz') | 
					
						
							|  |  |  |         install_path = self.mkdtemp() | 
					
						
							|  |  |  |         old_get_path = install.get_path | 
					
						
							|  |  |  |         install.get_path = lambda path: install_path | 
					
						
							|  |  |  |         old_mod = os.stat(install_path).st_mode | 
					
						
							|  |  |  |         os.chmod(install_path, 0) | 
					
						
							|  |  |  |         old_stderr = sys.stderr | 
					
						
							|  |  |  |         sys.stderr = StringIO() | 
					
						
							|  |  |  |         try: | 
					
						
							|  |  |  |             self.assertFalse(install.install(project)) | 
					
						
							|  |  |  |             self.assertEqual(main(['install', 'blabla']), 1) | 
					
						
							|  |  |  |         finally: | 
					
						
							|  |  |  |             sys.stderr = old_stderr | 
					
						
							|  |  |  |             os.chmod(install_path, old_mod) | 
					
						
							|  |  |  |             install.get_path = old_get_path | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-09-10 05:18:20 +02:00
										 |  |  |     def test_show_help(self): | 
					
						
							|  |  |  |         # smoke test, just makes sure some help is displayed | 
					
						
							|  |  |  |         status, out, err = assert_python_ok('-m', 'packaging.run', '--help') | 
					
						
							|  |  |  |         self.assertEqual(status, 0) | 
					
						
							|  |  |  |         self.assertGreater(out, b'') | 
					
						
							|  |  |  |         self.assertEqual(err, b'') | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-19 13:07:25 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | def test_suite(): | 
					
						
							| 
									
										
										
										
											2011-09-10 05:18:20 +02:00
										 |  |  |     return unittest.makeSuite(RunTestCase) | 
					
						
							| 
									
										
										
										
											2011-05-19 13:07:25 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | if __name__ == "__main__": | 
					
						
							|  |  |  |     unittest.main(defaultTest="test_suite") |