Server IP : 127.0.0.2 / Your IP : 18.119.122.86 Web Server : Apache/2.4.18 (Ubuntu) System : User : www-data ( ) PHP Version : 7.0.33-0ubuntu0.16.04.16 Disable Function : disk_free_space,disk_total_space,diskfreespace,dl,exec,fpaththru,getmyuid,getmypid,highlight_file,ignore_user_abord,leak,listen,link,opcache_get_configuration,opcache_get_status,passthru,pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,php_uname,phpinfo,posix_ctermid,posix_getcwd,posix_getegid,posix_geteuid,posix_getgid,posix_getgrgid,posix_getgrnam,posix_getgroups,posix_getlogin,posix_getpgid,posix_getpgrp,posix_getpid,posix,_getppid,posix_getpwnam,posix_getpwuid,posix_getrlimit,posix_getsid,posix_getuid,posix_isatty,posix_kill,posix_mkfifo,posix_setegid,posix_seteuid,posix_setgid,posix_setpgid,posix_setsid,posix_setuid,posix_times,posix_ttyname,posix_uname,pclose,popen,proc_open,proc_close,proc_get_status,proc_nice,proc_terminate,shell_exec,source,show_source,system,virtual MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /usr/lib/python3/dist-packages/distro_info_test/ |
Upload File : |
# test_help.py - Ensure scripts can run --help. # # Copyright (C) 2010, Stefano Rivera <stefanor@debian.org> # # Permission to use, copy, modify, and/or distribute this software for any # purpose with or without fee is hereby granted, provided that the above # copyright notice and this permission notice appear in all copies. # # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH # REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY # AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, # INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM # LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR # OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR # PERFORMANCE OF THIS SOFTWARE. import fcntl import os import select import signal import subprocess import time import setup from distro_info_test import unittest TIMEOUT = 5 def load_tests(loader, tests, pattern): "Give HelpTestCase a chance to populate before loading its test cases" suite = unittest.TestSuite() HelpTestCase.populate() suite.addTests(loader.loadTestsFromTestCase(HelpTestCase)) return suite class HelpTestCase(unittest.TestCase): @classmethod def populate(cls): for script in setup.SCRIPTS: setattr(cls, 'test_' + script, cls.make_help_tester(script)) @classmethod def make_help_tester(cls, script): def tester(self): null = open('/dev/null', 'r') process = subprocess.Popen(['./' + script, '--help'], close_fds=True, stdin=null, stdout=subprocess.PIPE, stderr=subprocess.PIPE) started = time.time() out = [] fds = [process.stdout.fileno(), process.stderr.fileno()] for fd in fds: fcntl.fcntl(fd, fcntl.F_SETFL, fcntl.fcntl(fd, fcntl.F_GETFL) | os.O_NONBLOCK) while time.time() - started < TIMEOUT: for fd in select.select(fds, [], fds, TIMEOUT)[0]: out.append(os.read(fd, 1024)) if process.poll() is not None: break if process.poll() is None: os.kill(process.pid, signal.SIGTERM) time.sleep(1) if process.poll() is None: os.kill(process.pid, signal.SIGKILL) null.close() self.assertEqual(process.poll(), 0, "%s failed to return usage within %i seconds.\n" "Output:\n%s" % (script, TIMEOUT, ''.encode('ascii').join(out))) process.stdout.close() process.stderr.close() return tester