1a2 > import pytest 5d5 < import unittest 7a8 > from conftest import option 15,16c16,17 < self.assertRegex(body, r'time: \d+', 'disable_functions before time') < self.assertRegex(body, r'exec: \/\w+', 'disable_functions before exec') --- > assert re.search(r'time: \d+', body), 'disable_functions before time' > assert re.search(r'exec: \/\w+', body), 'disable_functions before exec' 19,29c20,22 < self.assertIn( < 'success', < self.conf( < { < "admin": { < "opcache.enable": val, < "opcache.enable_cli": val, < }, < }, < 'applications/' + app + '/options', < ), --- > assert 'success' in self.conf( > {"admin": {"opcache.enable": val, "opcache.enable_cli": val,},}, > 'applications/' + app + '/options', 35,36c28 < print('opcache is not supported') < raise unittest.SkipTest() --- > pytest.skip('opcache is not supported') 38c30 < self.assertEqual(opcache, val, 'opcache value') --- > assert opcache == val, 'opcache value' 53c45 < url='/index.php/blah?var=val' --- > url='/index.php/blah?var=val', 56c48 < self.assertEqual(resp['status'], 200, 'status') --- > assert resp['status'] == 200, 'status' 59,64c51,54 < self.assertRegex(header_server, r'Unit/[\d\.]+', 'server header') < self.assertEqual( < headers.pop('Server-Software'), < header_server, < 'server software header', < ) --- > assert re.search(r'Unit/[\d\.]+', header_server), 'server header' > assert ( > headers.pop('Server-Software') == header_server > ), 'server software header' 67,72c57,60 < self.assertEqual(date[-4:], ' GMT', 'date header timezone') < self.assertLess( < abs(self.date_to_sec_epoch(date) - self.sec_epoch()), < 5, < 'date header', < ) --- > assert date[-4:] == ' GMT', 'date header timezone' > assert ( > abs(self.date_to_sec_epoch(date) - self.sec_epoch()) < 5 > ), 'date header' 78,92c66,76 < self.assertDictEqual( < headers, < { < 'Connection': 'close', < 'Content-Length': str(len(body)), < 'Request-Method': 'POST', < 'Path-Info': '/blah', < 'Request-Uri': '/index.php/blah?var=val', < 'Http-Host': 'localhost', < 'Server-Protocol': 'HTTP/1.1', < 'Custom-Header': 'blah', < }, < 'headers', < ) < self.assertEqual(resp['body'], body, 'body') --- > assert headers == { > 'Connection': 'close', > 'Content-Length': str(len(body)), > 'Request-Method': 'POST', > 'Path-Info': '/blah', > 'Request-Uri': '/index.php/blah?var=val', > 'Http-Host': 'localhost', > 'Server-Protocol': 'HTTP/1.1', > 'Custom-Header': 'blah', > }, 'headers' > assert resp['body'] == body, 'body' 99,103c83,85 < self.assertEqual( < resp['headers']['Query-String'], < 'var1=val1&var2=val2', < 'query string', < ) --- > assert ( > resp['headers']['Query-String'] == 'var1=val1&var2=val2' > ), 'query string' 110,113c92,93 < self.assertEqual(resp['status'], 200, 'query string empty status') < self.assertEqual( < resp['headers']['Query-String'], '', 'query string empty' < ) --- > assert resp['status'] == 200, 'query string empty status' > assert resp['headers']['Query-String'] == '', 'query string empty' 120,123c100,101 < self.assertEqual(resp['status'], 200, 'query string absent status') < self.assertEqual( < resp['headers']['Query-String'], '', 'query string absent' < ) --- > assert resp['status'] == 200, 'query string absent status' > assert resp['headers']['Query-String'] == '', 'query string absent' 130,131c108,109 < self.assertEqual(resp['status'], 200, 'status') < self.assertNotEqual(resp['body'], '', 'body not empty') --- > assert resp['status'] == 200, 'status' > assert resp['body'] != '', 'body not empty' 136c114 < self.assertEqual( --- > assert ( 143,146c121,123 < )['status'], < 404, < 'status', < ) --- > )['status'] > == 404 > ), 'status' 148c125 < self.assertEqual( --- > assert ( 155,158c132,134 < )['status'], < 404, < 'status case insensitive', < ) --- > )['status'] > == 404 > ), 'status case insensitive' 160c136 < self.assertEqual( --- > assert ( 167,170c143,145 < )['status'], < 404, < 'status version empty', < ) --- > )['status'] > == 404 > ), 'status version empty' 172d146 < 178,181c152,155 < self.assertEqual(resp['status'], 404, '404 status') < self.assertRegex( < resp['body'], r'404 Not Found', '404 body' < ) --- > assert resp['status'] == 404, '404 status' > assert re.search( > r'404 Not Found', resp['body'] > ), '404 body' 186c160 < self.assertEqual(self.get()['status'], 200, 'init') --- > assert self.get()['status'] == 200, 'init' 200c174 < self.assertEqual(resp['body'], body, 'keep-alive 1') --- > assert resp['body'] == body, 'keep-alive 1' 213c187 < self.assertEqual(resp['body'], body, 'keep-alive 2') --- > assert resp['body'] == body, 'keep-alive 2' 218,219c192,193 < self.assertRegex(self.get()['body'], r'True', 'conditional true') < self.assertRegex(self.post()['body'], r'False', 'conditional false') --- > assert re.search(r'True', self.get()['body']), 'conditional true' > assert re.search(r'False', self.post()['body']), 'conditional false' 225,228c199,202 < self.assertEqual(resp['headers']['X-Var-1'], 'val1', 'GET variables') < self.assertEqual(resp['headers']['X-Var-2'], '1', 'GET variables 2') < self.assertEqual(resp['headers']['X-Var-3'], '1', 'GET variables 3') < self.assertEqual(resp['headers']['X-Var-4'], '', 'GET variables 4') --- > assert resp['headers']['X-Var-1'] == 'val1', 'GET variables' > assert resp['headers']['X-Var-2'] == '1', 'GET variables 2' > assert resp['headers']['X-Var-3'] == '1', 'GET variables 3' > assert resp['headers']['X-Var-4'] == '', 'GET variables 4' 241,243c215,217 < self.assertEqual(resp['headers']['X-Var-1'], 'val1', 'POST variables') < self.assertEqual(resp['headers']['X-Var-2'], '1', 'POST variables 2') < self.assertEqual(resp['headers']['X-Var-3'], '', 'POST variables 3') --- > assert resp['headers']['X-Var-1'] == 'val1', 'POST variables' > assert resp['headers']['X-Var-2'] == '1', 'POST variables 2' > assert resp['headers']['X-Var-3'] == '', 'POST variables 3' 256,257c230,231 < self.assertEqual(resp['headers']['X-Cookie-1'], 'val', 'cookie') < self.assertEqual(resp['headers']['X-Cookie-2'], 'val2', 'cookie') --- > assert resp['headers']['X-Cookie-1'] == 'val', 'cookie' > assert resp['headers']['X-Cookie-2'] == 'val2', 'cookie' 262,264c236 < self.assertNotEqual( < self.get()['headers']['X-Precision'], '4', 'ini value default' < ) --- > assert self.get()['headers']['X-Precision'] != '4', 'ini value default' 270,277c242,246 < self.assertEqual( < self.get()['headers']['X-File'], < self.current_dir + '/php/ini_precision/ini/php.ini', < 'ini file', < ) < self.assertEqual( < self.get()['headers']['X-Precision'], '4', 'ini value' < ) --- > assert ( > self.get()['headers']['X-File'] > == option.test_dir + '/php/ini_precision/ini/php.ini' > ), 'ini file' > assert self.get()['headers']['X-Precision'] == '4', 'ini value' 279c248 < @unittest.skip('not yet') --- > @pytest.mark.skip('not yet') 283,290c252,255 < self.assertIn( < 'error', < self.conf( < {"user": {"precision": "4"}, "admin": {"precision": "5"}}, < 'applications/ini_precision/options', < ), < 'ini admin user', < ) --- > assert 'error' in self.conf( > {"user": {"precision": "4"}, "admin": {"precision": "5"}}, > 'applications/ini_precision/options', > ), 'ini admin user' 300,302c265 < self.assertEqual( < self.get()['headers']['X-Precision'], '5', 'ini value admin' < ) --- > assert self.get()['headers']['X-Precision'] == '5', 'ini value admin' 312,314c275 < self.assertEqual( < self.get()['headers']['X-Precision'], '5', 'ini value user' < ) --- > assert self.get()['headers']['X-Precision'] == '5', 'ini value user' 323,325c284 < self.assertEqual( < self.get()['headers']['X-Precision'], '4', 'ini user file' < ) --- > assert self.get()['headers']['X-Precision'] == '4', 'ini user file' 331,333c290 < self.assertEqual( < self.get()['headers']['X-Precision'], '5', 'ini value user' < ) --- > assert self.get()['headers']['X-Precision'] == '5', 'ini value user' 342,346c299,301 < self.assertEqual( < self.get(url='/?precision=6')['headers']['X-Precision'], < '5', < 'ini set admin', < ) --- > assert ( > self.get(url='/?precision=6')['headers']['X-Precision'] == '5' > ), 'ini set admin' 355,359c310,312 < self.assertEqual( < self.get(url='/?precision=6')['headers']['X-Precision'], < '6', < 'ini set user', < ) --- > assert ( > self.get(url='/?precision=6')['headers']['X-Precision'] == '6' > ), 'ini set user' 368,370c321 < self.assertEqual( < self.get()['headers']['X-Precision'], '5', 'ini value' < ) --- > assert self.get()['headers']['X-Precision'] == '5', 'ini value' 372,374c323 < self.assertEqual( < self.get()['headers']['X-Precision'], '5', 'ini value repeat' < ) --- > assert self.get()['headers']['X-Precision'] == '5', 'ini value repeat' 388,389c337,338 < self.assertRegex(body, r'time: \d+', 'disable_functions time') < self.assertNotRegex(body, r'exec: \/\w+', 'disable_functions exec') --- > assert re.search(r'time: \d+', body), 'disable_functions time' > assert not re.search(r'exec: \/\w+', body), 'disable_functions exec' 403,406c352,357 < self.assertNotRegex(body, r'time: \d+', 'disable_functions comma time') < self.assertNotRegex( < body, r'exec: \/\w+', 'disable_functions comma exec' < ) --- > assert not re.search( > r'time: \d+', body > ), 'disable_functions comma time' > assert not re.search( > r'exec: \/\w+', body > ), 'disable_functions comma exec' 420,423c371,376 < self.assertNotRegex(body, r'time: \d+', 'disable_functions space time') < self.assertNotRegex( < body, r'exec: \/\w+', 'disable_functions space exec' < ) --- > assert not re.search( > r'time: \d+', body > ), 'disable_functions space time' > assert not re.search( > r'exec: \/\w+', body > ), 'disable_functions space exec' 437,440c390,393 < self.assertRegex(body, r'time: \d+', 'disable_functions user time') < self.assertNotRegex( < body, r'exec: \/\w+', 'disable_functions user exec' < ) --- > assert re.search(r'time: \d+', body), 'disable_functions user time' > assert not re.search( > r'exec: \/\w+', body > ), 'disable_functions user exec' 454,459c407,412 < self.assertRegex( < body, r'time: \d+', 'disable_functions nonexistent time' < ) < self.assertRegex( < body, r'exec: \/\w+', 'disable_functions nonexistent exec' < ) --- > assert re.search( > r'time: \d+', body > ), 'disable_functions nonexistent time' > assert re.search( > r'exec: \/\w+', body > ), 'disable_functions nonexistent exec' 464,466c417,419 < self.assertRegex( < self.get()['body'], r'012345', 'disable_classes before' < ) --- > assert re.search( > r'012345', self.get()['body'] > ), 'disable_classes before' 473,475c426,428 < self.assertNotRegex( < self.get()['body'], r'012345', 'disable_classes before' < ) --- > assert not re.search( > r'012345', self.get()['body'] > ), 'disable_classes before' 480,482c433,435 < self.assertRegex( < self.get()['body'], r'012345', 'disable_classes before' < ) --- > assert re.search( > r'012345', self.get()['body'] > ), 'disable_classes before' 489,491c442,444 < self.assertNotRegex( < self.get()['body'], r'012345', 'disable_classes before' < ) --- > assert not re.search( > r'012345', self.get()['body'] > ), 'disable_classes before' 496c449 < self.assertEqual(self.get()['status'], 200, 'status') --- > assert self.get()['status'] == 200, 'status' 500c453 < self.assertEqual(self.get()['status'], 200, 'status 2') --- > assert self.get()['status'] == 200, 'status 2' 506c459 < self.assertIsNotNone(self.wait_for_record(pattern), 'errors print') --- > assert self.wait_for_record(pattern) is not None, 'errors print' 508c461 < with open(self.testdir + '/unit.log', 'r', errors='ignore') as f: --- > with open(self.temp_dir + '/unit.log', 'r', errors='ignore') as f: 511c464 < self.assertEqual(len(errs), 2, 'error_log count') --- > assert len(errs) == 2, 'error_log count' 515c468 < self.assertNotEqual(date, date2, 'date diff') --- > assert date != date2, 'date diff' 518,534c471,483 < self.assertIn( < 'success', < self.conf( < { < "listeners": {"*:7080": {"pass": "applications/script"}}, < "applications": { < "script": { < "type": "php", < "processes": {"spare": 0}, < "root": self.current_dir + "/php/script", < "script": "phpinfo.php", < } < }, < } < ), < 'configure script', < ) --- > assert 'success' in self.conf( > { > "listeners": {"*:7080": {"pass": "applications/script"}}, > "applications": { > "script": { > "type": "php", > "processes": {"spare": 0}, > "root": option.test_dir + "/php/script", > "script": "phpinfo.php", > } > }, > } > ), 'configure script' 538,539c487,488 < self.assertEqual(resp['status'], 200, 'status') < self.assertNotEqual(resp['body'], '', 'body not empty') --- > assert resp['status'] == 200, 'status' > assert resp['body'] != '', 'body not empty' 542,557c491,502 < self.assertIn( < 'success', < self.conf( < { < "listeners": {"*:7080": {"pass": "applications/phpinfo"}}, < "applications": { < "phpinfo": { < "type": "php", < "processes": {"spare": 0}, < "root": self.current_dir + "/php/phpinfo", < } < }, < } < ), < 'configure index default', < ) --- > assert 'success' in self.conf( > { > "listeners": {"*:7080": {"pass": "applications/phpinfo"}}, > "applications": { > "phpinfo": { > "type": "php", > "processes": {"spare": 0}, > "root": option.test_dir + "/php/phpinfo", > } > }, > } > ), 'configure index default' 561,562c506,507 < self.assertEqual(resp['status'], 200, 'status') < self.assertNotEqual(resp['body'], '', 'body not empty') --- > assert resp['status'] == 200, 'status' > assert resp['body'] != '', 'body not empty' 567,569c512 < self.assertNotEqual( < self.get(url='/index.wrong')['status'], 200, 'status' < ) --- > assert self.get(url='/index.wrong')['status'] != 200, 'status' 571c514 < new_root = self.testdir + "/php" --- > new_root = self.temp_dir + "/php" 573c516 < shutil.copy(self.current_dir + '/php/phpinfo/index.wrong', new_root) --- > shutil.copy(option.test_dir + '/php/phpinfo/index.wrong', new_root) 575,591c518,530 < self.assertIn( < 'success', < self.conf( < { < "listeners": {"*:7080": {"pass": "applications/phpinfo"}}, < "applications": { < "phpinfo": { < "type": "php", < "processes": {"spare": 0}, < "root": new_root, < "working_directory": new_root, < } < }, < } < ), < 'configure new root', < ) --- > assert 'success' in self.conf( > { > "listeners": {"*:7080": {"pass": "applications/phpinfo"}}, > "applications": { > "phpinfo": { > "type": "php", > "processes": {"spare": 0}, > "root": new_root, > "working_directory": new_root, > } > }, > } > ), 'configure new root' 594,596c533 < self.assertNotEqual( < str(resp['status']) + resp['body'], '200', 'status new root' < ) --- > assert str(resp['status']) + resp['body'] != '200', 'status new root' 599,600c536,537 < self.assertIn( < 'success', self.conf_delete('applications/cwd/working_directory') --- > assert 'success' in self.conf_delete( > 'applications/cwd/working_directory' 603c540 < script_cwd = self.current_dir + '/php/cwd' --- > script_cwd = option.test_dir + '/php/cwd' 606,607c543,544 < self.assertEqual(resp['status'], 200, 'status ok') < self.assertEqual(resp['body'], script_cwd, 'default cwd') --- > assert resp['status'] == 200, 'status ok' > assert resp['body'] == script_cwd, 'default cwd' 609,614c546,547 < self.assertIn( < 'success', < self.conf( < '"' + self.current_dir + '"', < 'applications/cwd/working_directory', < ), --- > assert 'success' in self.conf( > '"' + option.test_dir + '"', 'applications/cwd/working_directory', 618,619c551,552 < self.assertEqual(resp['status'], 200, 'status ok') < self.assertEqual(resp['body'], script_cwd, 'wdir cwd') --- > assert resp['status'] == 200, 'status ok' > assert resp['body'] == script_cwd, 'wdir cwd' 622,623c555,556 < self.assertEqual(resp['status'], 200, 'status ok') < self.assertEqual(resp['body'], '/', 'cwd after chdir') --- > assert resp['status'] == 200, 'status ok' > assert resp['body'] == '/', 'cwd after chdir' 628,629c561,562 < self.assertEqual(resp['status'], 200, 'status ok') < self.assertEqual(resp['body'], script_cwd, 'cwd restored') --- > assert resp['status'] == 200, 'status ok' > assert resp['body'] == script_cwd, 'cwd restored' 632,634c565 < self.assertEqual( < resp['body'], script_cwd + '/subdir', 'cwd subdir', < ) --- > assert resp['body'] == script_cwd + '/subdir', 'cwd subdir' 653c584 < script_cwd = self.current_dir + '/php/cwd' --- > script_cwd = option.test_dir + '/php/cwd' 655,656c586,587 < self.assertIn( < 'success', self.conf_delete('applications/cwd/working_directory') --- > assert 'success' in self.conf_delete( > 'applications/cwd/working_directory' 659,661c590 < self.assertIn( < 'success', self.conf('"index.php"', 'applications/cwd/script') < ) --- > assert 'success' in self.conf('"index.php"', 'applications/cwd/script') 663,665c592 < self.assertEqual( < self.get()['body'], script_cwd, 'default cwd', < ) --- > assert self.get()['body'] == script_cwd, 'default cwd' 667,669c594 < self.assertEqual( < self.get(url='/?chdir=/')['body'], '/', 'cwd after chdir', < ) --- > assert self.get(url='/?chdir=/')['body'] == '/', 'cwd after chdir' 672c597 < self.assertEqual(self.get()['body'], script_cwd, 'cwd restored') --- > assert self.get()['body'] == script_cwd, 'cwd restored' 691c616 < self.assertEqual(self.get()['body'], 'test', 'relative path') --- > assert self.get()['body'] == 'test', 'relative path' 693,695c618,620 < self.assertNotEqual( < self.get(url='/?chdir=/')['body'], 'test', 'relative path w/ chdir' < ) --- > assert ( > self.get(url='/?chdir=/')['body'] != 'test' > ), 'relative path w/ chdir' 697,701c622 < self.assertEqual(self.get()['body'], 'test', 'relative path 2') < < < if __name__ == '__main__': < TestPHPApplication.main() --- > assert self.get()['body'] == 'test', 'relative path 2'