Best Python code snippet using avocado_python
about-me2
Source:about-me2  
...86        action='version',87        version='{0}: v{1} by {2}'.format('%(prog)s', __version__, __author__)88    )89    return parser.parse_args()90def find_command(return_text, cmd, version_regex=None, ignore_output=False):91    success, result = lib.base2.shell_exec(cmd)92    if not success:93        return ''94    stdout, stderr, retc = result95    if ignore_output:96        if retc == 0:97            return '* {}\n'.format(return_text.strip())98        else:99            return ''100    if stdout == '' and stderr != '':101        # https://stackoverflow.com/questions/26028416/why-does-python-print-version-info-to-stderr102        # https://stackoverflow.com/questions/13483443/why-does-java-version-go-to-stderr103        stdout = stderr104    stdout = stdout.strip().splitlines()[0].strip()105    # where to find the version number in output?106    if version_regex:107        re_search = re.search(version_regex, stdout)108        if re_search:109            try:110                return '* {} {}\n'.format(return_text, re_search.group(1).strip())111            except IndexError:112                # this means there is no group 1, so return the whole match113                return '* {} {}\n'.format(return_text, re_search.group(0).strip())114    return '* {} {}\n'.format(return_text, stdout)115def get_sys_dimensions():116    """get some very basic system statistics117    """118    sys_dimensions = {}119    sys_dimensions['cpu'] = psutil.cpu_count(logical=True)120    sys_dimensions['ram'] = psutil.virtual_memory().total121    return sys_dimensions122def get_disks():123    msg = ''124    stdout, stderr, retc = lib.base2.coe(lib.base2.shell_exec('lsblk --nodeps --output NAME,SIZE --noheadings --include 8,252,259'))125    for disk in stdout.strip().splitlines():126        # zRAM devices can appear in the output of lsblk, but127        # we cannot do anything useful with them128        if disk.startswith('zram'):129            continue130        msg += '* {}\n'.format(disk)131    return msg132def get_apps():133    """ try to find some (manual installed)  applications - here called "apps";134    mainly found in /home, /opt or /var/www/html;135    just guessing and without version info136    """137    apps = ''138    apps += '* Apache Tomcat\n'                   if os.path.isdir('/opt/apache-tomcat') else ''139    apps += '* Apache Tomcat\n'                   if os.path.isdir('/opt/tomcat') else ''140    apps += '* Atlassian Bitbucket\n'             if os.path.isdir('/opt/atlassian/bitbucket') else ''141    apps += '* Atlassian Confluence\n'            if os.path.isdir('/opt/atlassian/confluence') else ''142    apps += '* Atlassian Jira\n'                  if os.path.isdir('/opt/atlassian/jira') else ''143    apps += '* Atomicorp\n'                       if os.path.isdir('/opt/atomicorp') else ''144    apps += '* Bacchus\n'                         if os.path.isdir('/opt/bacchus') else ''145    apps += '* BizBus\n'                          if os.path.isdir('/opt/bizbus') else ''146    apps += '* Brother Printer SW\n'              if os.path.isdir('/opt/brother') else ''147    apps += '* Collabora Office 5.0\n'            if os.path.isdir('/opt/collaboraoffice5.0') else ''148    apps += '* Collabora Office 5.1\n'            if os.path.isdir('/opt/collaboraoffice5.1') else ''149    apps += '* Collabora Office 5.3\n'            if os.path.isdir('/opt/collaboraoffice5.3') else ''150    apps += '* Collabora Office 6.0\n'            if os.path.isdir('/opt/collaboraoffice6.0') else ''151    apps += '* Collabora Office 6.2\n'            if os.path.isdir('/opt/collaboraoffice6.2') else ''152    apps += '* Collabora Office 6.4\n'            if os.path.isdir('/opt/collaboraoffice6.4') else ''153    apps += '* Contao\n'                          if os.path.isdir('/var/www/html/contao') else ''154    apps += '* DCM4CHEE\n'                        if os.path.isdir('/opt/dcm4chee') else ''155    apps += '* Django\n'                          if os.path.isdir('/opt/django') else ''156    apps += '* Elasticsearch\n'                   if os.path.isfile('/usr/share/elasticsearch/bin/elasticsearch') else ''157    apps += '* F5 VPN SW\n'                       if os.path.isdir('/opt/f5/vpn') else ''158    apps += '* GitLab\n'                          if os.path.isdir('/opt/gitlab') else ''159    apps += '* Google Chrome\n'                   if os.path.isdir('/opt/google/chrome') else ''160    apps += '* Graylog Server\n'                  if os.path.isfile('/usr/share/graylog-server/bin/graylog-server') else ''161    apps += '* H-Net SecureService (eFaktura)\n'  if os.path.isdir('/home/hnet/HnetSecureService') else ''162    apps += '* Hostbill\n'                        if os.path.isdir('/home/hostbill') else ''163    apps += '* HTMLy\n'                           if os.path.isdir('/var/www/html/htmly') else ''164    apps += '* JBoss\n'                           if os.path.isdir('/opt/jboss') else ''165    apps += '* JumpCloud\n'                       if os.path.isdir('/opt/jc') else ''166    apps += '* KeeWeb\n'                          if os.path.isdir('/opt/KeeWeb') else ''167    apps += '* Keycloak\n'                        if os.path.isdir('/opt/keycloak') else ''168    apps += '* LibreNMS\n'                        if os.path.isdir('/opt/librenms') else ''169    apps += '* MariaDB ColumnStore\n'             if os.path.isdir('/opt/columnstore') else ''170    apps += '* Matomo\n'                          if os.path.isdir('/var/www/html/matomo') else ''171    apps += '* MediaWiki\n'                       if os.path.isdir('/var/www/html/mediawiki') else ''172    apps += '* Medidata (eFaktura)\n'             if os.path.isdir('/opt/MPCommunicator') else ''173    apps += '* Metabase\n'                        if os.path.isdir('/opt/metabase') else ''174    apps += '* Nextcloud\n'                       if os.path.isdir('/var/www/html/nextcloud') else ''175    apps += '* NodeBB\n'                          if os.path.isdir('/opt/nodebb') else ''176    apps += '* PHP 7.0 (RH)\n'                    if os.path.isdir('/opt/rh/rh-php70') else ''177    apps += '* PHP 7.1 (RH)\n'                    if os.path.isdir('/opt/rh/rh-php71') else ''178    apps += '* PHP 7.2 (RH)\n'                    if os.path.isdir('/opt/rh/rh-php72') else ''179    apps += '* PHP 7.3 (RH)\n'                    if os.path.isdir('/opt/rh/rh-php73') else ''180    apps += '* PHP 7.4 (RH)\n'                    if os.path.isdir('/opt/rh/rh-php74') else ''181    apps += '* PHP 8.0 (RH)\n'                    if os.path.isdir('/opt/rh/rh-php80') else ''182    apps += '* PHP 8.1 (RH)\n'                    if os.path.isdir('/opt/rh/rh-php81') else ''183    apps += '* Piwik\n'                           if os.path.isdir('/var/www/html/piwik') else ''184    apps += '* PostgreSQL 7.2 (RH)\n'             if os.path.isdir('/opt/rh/rh-postgresql72') else ''185    apps += '* PostgreSQL 7.3 (RH)\n'             if os.path.isdir('/opt/rh/rh-postgresql73') else ''186    apps += '* PostgreSQL 7.4 (RH)\n'             if os.path.isdir('/opt/rh/rh-postgresql74') else ''187    apps += '* PostgreSQL 8.0 (RH)\n'             if os.path.isdir('/opt/rh/rh-postgresql80') else ''188    apps += '* PostgreSQL 8.1 (RH)\n'             if os.path.isdir('/opt/rh/rh-postgresql81') else ''189    apps += '* PostgreSQL 8.2 (RH)\n'             if os.path.isdir('/opt/rh/rh-postgresql82') else ''190    apps += '* PostgreSQL 8.3 (RH)\n'             if os.path.isdir('/opt/rh/rh-postgresql83') else ''191    apps += '* PostgreSQL 8.4 (RH)\n'             if os.path.isdir('/opt/rh/rh-postgresql84') else ''192    apps += '* PostgreSQL 9.0 (RH)\n'             if os.path.isdir('/opt/rh/rh-postgresql90') else ''193    apps += '* PostgreSQL 9.1 (RH)\n'             if os.path.isdir('/opt/rh/rh-postgresql91') else ''194    apps += '* PostgreSQL 9.2 (RH)\n'             if os.path.isdir('/opt/rh/rh-postgresql92') else ''195    apps += '* PostgreSQL 9.3 (RH)\n'             if os.path.isdir('/opt/rh/rh-postgresql93') else ''196    apps += '* PostgreSQL 9.4 (RH)\n'             if os.path.isdir('/opt/rh/rh-postgresql94') else ''197    apps += '* PostgreSQL 9.5 (RH)\n'             if os.path.isdir('/opt/rh/rh-postgresql95') else ''198    apps += '* PostgreSQL 9.6 (RH)\n'             if os.path.isdir('/opt/rh/rh-postgresql96') else ''199    apps += '* Rambox\n'                          if os.path.isdir('/opt/Rambox') else ''200    apps += '* Rocket.Chat\n'                     if os.path.isdir('/opt/Rocket.Chat') else ''201    apps += '* Roundcube\n'                       if os.path.isdir('/var/www/html/roundcubemail') else ''202    apps += '* Tarifpool\n'                       if os.path.isdir('/opt/tarifpool') else ''203    apps += '* VMware Tools\n'                    if os.path.isdir('/etc/vmware-tools') else ''204    apps += '* Vtiger\n'                          if os.path.isdir('/var/www/html/vtigercrm') else ''205    apps += '* WildFly\n'                         if os.path.isdir('/opt/wildfly') else ''206    apps += '* WordPress\n'                       if os.path.isdir('/var/www/html/wordpress/wp-config.php') else ''207    apps += '* WordPress\n'                       if os.path.isdir('/var/www/html/wp-config.php') else ''208    apps += '* Yii2\n'                            if os.path.isdir('/var/www/html/yii2') else ''209    apps += '* Yii2\n'                            if os.path.isdir('/var/www/html/yii2-advanced') else ''210    apps += '* Yii2\n'                            if os.path.isdir('/var/www/html/yii2-basic') else ''211    apps += '* Yii\n'                             if os.path.isdir('/var/www/html/yii') else ''212    apps += '* Zimbra\n'                          if os.path.isdir('/opt/zimbra') else ''213    return apps214def get_tools():215    """ simple tools, alphabetically sorted by output216    """217    tools = ''218    tools += find_command('dig',       'command -v dig', ignore_output=True)219    tools += find_command('hdparm',    'command -v hdparm', ignore_output=True)220    tools += find_command('iftop',     'command -v iftop', ignore_output=True)221    tools += find_command('lsof',      'command -v lsof', ignore_output=True)222    tools += find_command('nano',      'command -v nano', ignore_output=True)223    tools += find_command('ncat',      'command -v ncat', ignore_output=True)224    tools += find_command('nmap',      'command -v nmap', ignore_output=True)225    tools += find_command('rsync',     'command -v rsync', ignore_output=True)226    tools += find_command('tcpdump',   'command -v tcpdump', ignore_output=True)227    tools += find_command('telnet',    'command -v telnet', ignore_output=True)228    tools += find_command('tmux',      'command -v tmux', ignore_output=True)229    tools += find_command('unzip',     'command -v unzip', ignore_output=True)230    tools += find_command('vim',       'command -v vim', ignore_output=True)231    tools += find_command('wget',      'command -v wget', ignore_output=True)232    tools += find_command('whois',     'command -v whois', ignore_output=True)233    tools += find_command('wireshark', 'command -v tshark', ignore_output=True)234    return tools235def get_sw():236    """ applications, alphabetically sorted by output, callable with version info.237    """238    sw = ''239    sw += find_command('Apache httpd',              'httpd -v',                           version_regex =r'Apache/(.*) ')240    sw += find_command('Apache Tomcat',             'tomcat version',                     version_regex =r'Server version: Apache Tomcat/(.*)')241    sw += find_command('BIND',                      'named -v',                           version_regex =r'^BIND (.*?)-')242    sw += find_command('Borg',                      'borg --version',                     version_regex =r' (.*)')243    sw += find_command('ClamAV',                    'clamd --version',                    version_regex =r' (.*) ')244    sw += find_command('chrony',                    'chrony --version',                   version_regex =r'n ([\d\.]+)')245    sw += find_command('cockpit',                   '/usr/libexec/cockpit-ws --version',  version_regex =r': ([\d\.]+)')246    sw += find_command('coturn',                    'command -v turnserver',              ignore_output=True)247    sw += find_command('Containerd',                'containerd --version',               version_regex =r'\.io (.*) ')248    sw += find_command('Docker Compose',            'docker-compose --version',           version_regex =r' version (.*?),')249    sw += find_command('Docker/Podman',             'docker --version',                   version_regex =r' (\d+\d?\.\d+\d?.\d+\d?)')250    sw += find_command('Erlang',                    "erl -eval 'erlang:display(erlang:system_info(otp_release)), halt().'  -noshell",  version_regex =r'\"(.*)\"')251    sw += find_command('Elastic-Filebeat',          'filebeat version',                   version_regex =r'n ([\d\.]+)')252    sw += find_command('Fail2ban Server',           'fail2ban-server --version',          version_regex =r' v(.*)')253    sw += find_command('Firefox',                   'firefox --version',                  version_regex =r' Firefox (.*)')254    sw += find_command('FreeIPA',                   'ipa --version',                      version_regex =r' (.*?),')255    sw += find_command('g++',                       'g++ --version',                      version_regex =r'\) ([\d\.]+)')256    sw += find_command('gcc',                       'gcc --version',                      version_regex =r'\) ([\d\.]+)')257    sw += find_command('Git',                       'git --version',                      version_regex =r'git version (.*)')258    sw += find_command('Glances',                   'glances --version',                  version_regex =r'Glances v(.*?) ')259    sw += find_command('GNOME Display Manager',     'gdm --version ',                     version_regex =r' \S*')260    sw += find_command('GNOME Shell',               'gnome-shell --version',              version_regex =r'l (\S*)')261    sw += find_command('Grafana Server',            'grafana-server -v',                  version_regex =r'Version (.*?) ')262    sw += find_command('i3',                        'i3 --version',                       version_regex =r'version (\S+)')263    sw += find_command('Icinga2',                   'icinga2 --version',                  version_regex =r'\(version: (.*)\)')264    sw += find_command('InfluxDB',                  'influx --version',                   version_regex =r': (.*)')265    sw += find_command('Java',                      'java -version',                      version_regex =r'(.*)').replace('version ', '').replace('"', '')266    sw += find_command('LibreOffice Online (LOOL)', 'command -v loolwsd',                 ignore_output=True)267    sw += find_command('LibreOffice',               'libreoffice --version',              version_regex =r' (.*?) ')268    sw += find_command('Lighttpd',                  'lighttpd -v',                        version_regex =r'lighttpd/(.*) -')269    sw += find_command('Linux Kernel',              'uname -r')270    tmp = find_command('MySQL',                     'mysqld --version',                   version_regex =r'Ver (.*?) ')271    if 'MariaDB' in tmp:272        tmp = tmp.replace('MySQL', 'MariaDB').replace('-MariaDB', '')273    sw += tmp274    sw += find_command('MongoDB',                   'mongod --version',                   version_regex =r'db version v(.*?)\n')275    sw += find_command('mydumper/myloader',         'mydumper --version',                 version_regex =r' (.*?),')276    sw += find_command('Nginx',                     'nginx -v',                           version_regex =r'nginx version: nginx/(.*)')277    sw += find_command('Nikto',                     'nikto -Version',                     version_regex =r'main\s*(.*)')278    sw += find_command('Node',                      'node --version',                     version_regex =r'v(.*)')279    sw += find_command('NodeJS',                    'nodejs --version',                   version_regex =r'v(.*)')280    sw += find_command('npm',                       'npm --version',                      version_regex =r'(.*)')281    sw += find_command('ntpd',                      'ntpq -c version',                    version_regex =r' ([\d\.p]+)@')282    sw += find_command('OpenSSL',                   'openssl version',                    version_regex =r' (.*?) ')283    sw += find_command('OpenVAS',                   'openvas version',                    version_regex =r' (.*?)$')284    sw += find_command('OpenVPN',                   'openvpn --version',                  version_regex =r'N (\d+\.\d+(\.\d+)?)')285    sw += find_command('Open Virtual Machine Tools','vmtoolsd --version',                 version_regex =r'n ([\d\.]+)')286    sw += find_command('Perl',                      'perl --version',                     version_regex =r' \(v(.*?)\) ')287    sw += find_command('PHP',                       'php --version',                      version_regex =r'PHP (.*?) \(.*')288    sw += find_command('PHP-FPM',                   'php-fpm --version',                  version_regex =r'PHP (.*?) \(.*')289    sw += find_command('pip',                       'pip --version',                      version_regex =r'pip (.*) from')290    sw += find_command('Postfix',                   'postconf -d mail_version',           version_regex =r'= ([\d\.]+)')291    sw += find_command('PostgreSQL',                'psql --version',                     version_regex =r'\(PostgreSQL\) (.*)')292    sw += find_command('Python mapped to',          'python --version',                   version_regex =r' (.*)')293    sw += find_command('Python2',                   'python2 --version',                  version_regex =r' (.*)')294    sw += find_command('Python3',                   'python3 --version',                  version_regex =r' (.*)')295    sw += find_command('QEMU Guest Agent',          'qemu-ga --version',                  version_regex =r'([\d\.]+)')296    sw += find_command('RabbitMQ Server',           'rabbitmqctl version')297    sw += find_command('Redis Server',              'redis-server --version',             version_regex =r' v=(.*?) ')298    sw += find_command('SPICE Agent',               'command -v spice-vdagentd',          ignore_output=True)299    sw += find_command('ssh',                       'ssh -V',                             version_regex =r'_(.+),')300    sw += find_command('Sublime Text',              'subl --version',                     version_regex =r'.* (.*)$')301    sw += find_command('sudo',                      'sudo --version',                     version_regex =r'n (.+)')302    sw += find_command('systemd',                   'systemctl --version',                version_regex =r'systemd (\d+)')303    sw += find_command('Samba',                     'smbd --version',                     version_regex =r'n ([\d\.]+)')304    sw += find_command('TeamViewer',                'teamviewer --version',               version_regex =r'.* (\S*)  ')305    sw += find_command('tmate',                     'tmate -V',                           version_regex =r' (.*)')306    sw += find_command('Veeam',                     'veeamagent --version',               version_regex =r'(.*)')307    return sw308def get_os_info():309    release_files = [310        '/etc/centos-release',311        '/etc/fedora-release',312        '/etc/redhat-release',313        '/etc/system-release',314    ]315    for release_file in release_files:316        if os.path.isfile(release_file):317            return lib.base2.coe(lib.disk2.read_file(release_file)).strip()318    success, result = lib.base2.shell_exec('. /etc/os-release && echo $NAME $VERSION', shell=True)319    if success:320        stdout, stderr, retc = result...test_cmake.py
Source:test_cmake.py  
...12    args = [iter(iterable)] * n13    return itertools.zip_longest(*args, fillvalue=fillvalue)14class GenerateTargetTest(TestCase):15    def _check_target_no_test(self, cmake, name, path, deps, components):16        _, command = find_command(cmake, 'add_library', [name])17        assert(name == command[0])18        for index, component in enumerate(components):19            assert(component['source'] == command[index + 1])20        _, command = find_command(cmake, 'target_include_directories', [name])21        assert(name     == command[0])22        assert('PUBLIC' == command[1])23        # Note: CMake supports '/' for path separators on Windows (in addition24        # to Unix), so for simplicity we use '/' universally25        upath = path.replace('\\', '/')26        assert(upath    == command[2])27        _, command = find_command(cmake, 'target_link_libraries', [name])28        assert(name     == command[0])29        assert('PUBLIC' == command[1])30        for index, dep in enumerate(deps):31            assert(dep.name == command[index + 2])32        for _, command in find_commands(cmake, 'install', ['FILES']):33            assert('FILES'       == command[0])34            headers = [c['header'] for c in components if c['header'] != None]35            index = 136            for header in headers:37                assert(header == command[index])38                index += 139            assert('DESTINATION' == command[index + 0])40            assert('include'     == command[index + 1])41        _, command = find_command(cmake, 'install', ['TARGETS',42                                                     name,43                                                     'COMPONENT',44                                                     'development'])45        assert('TARGETS'     == command[0])46        assert(name          == command[1])47        assert('COMPONENT'   == command[2])48        assert('development' == command[3])49        assert('DESTINATION' == command[4])50        assert('lib'         == command[5])51        _, command = find_command(cmake, 'install', ['TARGETS',52                                                     name,53                                                     'COMPONENT',54                                                     'runtime'])55        assert('TARGETS'     == command[0])56        assert(name          == command[1])57        assert('COMPONENT'   == command[2])58        assert('runtime'     == command[3])59        assert('DESTINATION' == command[4])60        assert('.'           == command[5])61    def _check_target_drivers(self, cmake, name, components):62        drivers = [c['driver'] for c in components if c['driver'] != None]63        for driver in drivers:64            executable = splitext(driver)[0]65            _, command = find_command(cmake, 'add_executable', [executable])66            assert('EXCLUDE_FROM_ALL' == command[1])67            assert(driver             == command[2])68            executable = splitext(driver)[0]69            _, command = find_command(cmake,70                                      'target_link_libraries',71                                      [executable])72            assert(name == command[1])73    def _check_test_target(self, cmake, name, components):74        drivers = [c['driver'] for c in components if c['driver'] != None]75        if len(drivers):76            find_command(cmake, 'add_custom_target', [name + '.t'])77        else:78            with self.assertRaises(LookupError):79                find_command(cmake, 'add_custom_target', [name + '.t'])80    def _check_target_deps(self, cmake, name, dependencies):81        _, command = find_command(cmake, 'target_link_libraries')82        assert(name     == command[0])83        assert('PUBLIC' == command[1])84        for index, dep in enumerate(dependencies):85            assert(dep == command[index + 2])86    def _check_package(self, cmake, name, path, deps, comps):87        self._check_target_no_test(cmake, name, path, deps, comps)88        self._check_target_drivers(cmake, name, comps)89        self._check_test_target(cmake, name, comps)90    def _test_package(self, name, path, deps, comps, has_tests):91        target = Package(path, deps, comps)92        out = StringIO()93        generate([target], out)94        cmake = list(lex(out))95        self._check_package(cmake, name, path, deps, comps)96        if has_tests:97            find_command(cmake, 'add_custom_target', ['tests'])98        else:99            with self.assertRaises(LookupError):100                find_command(cmake, 'add_custom_target', ['tests'])101    def test_base_target_no_deps(self):102        t = Target('t', [])103        out = StringIO()104        generate([t], out)105        assert(out.getvalue())106    def test_cmake_prologue(self):107        t = Target('t', [])108        out = StringIO()109        generate([t], out)110        cmake = list(lex(out))111        find_command(cmake, 'cmake_minimum_required')112        find_command(cmake, 'project')113        find_command(cmake, 'conan_basic_setup')114    def test_empty_package_no_deps_no_test(self):115        self._test_package('target', pjoin('path', 'target'), [], [], False)116    def test_one_comp_package_no_deps_no_test(self):117        comps = [{ 'header': 'file.h',118                   'source': 'file.cpp',119                   'driver': None }]120        self._test_package('target', pjoin('path', 'target'), [], comps, False)121    def test_application(self):122        name  = 'app'123        path  = pjoin('path', 'app')124        deps = [Target('foo', [])]125        comps = [{ 'header': None,126                   'source': 'file.m.cpp',127                   'driver': None }]128        target = Application(path, deps, comps)129        out = StringIO()130        generate([target], out)131        cmake = list(lex(out))132        find_command(cmake, 'add_executable', [name, f'file.m.cpp'])133        find_command(cmake, 'target_link_libraries', [name, 'PUBLIC', 'foo'])134    def test_one_comp_package_no_deps_test(self):135        comps = [{ 'header': 'file.h',136                   'source': 'file.cpp',137                   'driver': 'file.t.cpp' }]138        self._test_package('target', pjoin('path', 'target'), [], comps, True)139    def test_one_comp_package_no_deps_plugin_test(self):140        comps = [{ 'header': 'file.h',141                   'source': 'file.cpp',142                   'driver': 'file.t.cpp' }]143        target = Package(pjoin('path', 'target'), [], comps)144        target.plugin_tests = True145        out = StringIO()146        generate([target], out)147        cmake = list(lex(out))148        find_command(cmake, 'add_library', ['file.t', 'SHARED'])149        find_command(cmake, 'target_link_libraries', ['file.t', 'target'])150        apple_start, _ = find_command(cmake, 'if', ['APPLE'])151        stmts = parse(iter(cmake[apple_start:]))[0]152        _, props = find_command(stmts[1], 'set_target_properties')153        assert(['file.t',154                'PROPERTIES',155                'LINK_FLAGS',156                '"-undefined',157                'dynamic_lookup"'] == props)158        win32_start, _ = find_command(cmake, 'if', ['WIN32'])159        stmts = parse(iter(cmake[win32_start:]))[0]160        _, props = find_command(stmts[1], 'target_link_options')161        assert(['file.t', 'PUBLIC', '/EXPORT:main'] == props)162    def test_empty_package_one_dep_no_test(self):163        deps = [Target('foo', [])]164        self._test_package('target', pjoin('path', 'target'), deps, [], False)165    def test_two_empty_packages_no_deps_no_test(self):166        deps1  = []167        comps1 = []168        p1 = Package('p1', deps1, comps1)169        deps2  = []170        comps2 = []171        p2 = Package('p2', deps2, comps2)172        is_test = False173        out = StringIO()174        generate([p1, p2], out)175        cmake = list(lex(out))176        self._check_package(cmake, 'p1', 'p1', deps1, comps1)177        self._check_package(cmake, 'p2', 'p2', deps2, comps2)178    def test_empty_package_with_override(self):179        p = Package('p', [], [])180        p.overrides = 'override.cmake'181        out = StringIO()182        generate([p], out)183        assert(f'include({p.overrides})' in out.getvalue())184    def test_empty_package_with_no_output_dep(self):185        p1 = Package('p1', [],   [])186        p2 = Package('p2', [p1], [])187        p1.has_output = False188        out = StringIO()189        generate([p1, p2], out)190        cmake = list(lex(out))191        _, libs = find_command(cmake, 'target_link_libraries', ['p2'])192        assert('p1' not in libs)193    def test_empty_package_lazily_bound(self):194        p = Package('p', [], [])195        p.lazily_bound = True196        out = StringIO()197        generate([p], out)198        commands = list(lex(out))199        apple_start, _ = find_command(commands, 'if', ['APPLE'])200        stmts = parse(iter(commands[apple_start:]))[0]201        _, props = find_command(stmts[1], 'set_target_properties')202        assert(['p',203                'PROPERTIES',204                'LINK_FLAGS',205                '"-undefined',206                'dynamic_lookup"'] == props)207    def test_cmake_target(self):208        path = pjoin('foo', 'bar')209        c = CMake('bar', path, [])210        out = StringIO()211        generate([c], out)212        # Note: CMake supports '/' for path separators on Windows (in addition213        # to Unix), so for simplicity we use '/' universally214        upath = path.replace('\\', '/')215        assert(f'add_subdirectory({upath} {c.name})' in out.getvalue())216    def test_no_pkg_config_no_include(self):217        c = CMake('foo', 'bar', [])218        out = StringIO()219        generate([c], out)220        assert('include(FindPkgConfig)' not in out.getvalue())221    def test_pkg_config_has_include(self):222        p = Pkg('foo', 'bar', [])223        out = StringIO()224        generate([p], out)225        assert('include(FindPkgConfig)' in out.getvalue())226    def test_pkg_config_generates_cmake(self):227        name    = 'foo'228        package = 'bar'229        p = Pkg(name, package, [])230        out = StringIO()231        generate([p], out)232        assert(out.getvalue())233    def test_pkg_config_generates_search(self):234        name    = 'foo'235        package = 'bar'236        p = Pkg(name, package, [])237        out = StringIO()238        generate([p], out)239        cmake = out.getvalue()240        assert(f'pkg_check_modules({name} REQUIRED {package})' in cmake)241    def test_pkg_config_generates_interface_lib(self):242        name    = 'foo'243        package = 'bar'244        p = Pkg(name, package, [])245        out = StringIO()246        generate([p], out)247        cmake = list(lex(out))248        _, command = find_command(cmake, 'add_library')249        assert(name == command[0])250        assert('INTERFACE' == command[1])251    def test_pkg_config_generates_shared_props(self):252        name    = 'foo'253        package = 'bar'254        p = Pkg(name, package, [])255        out = StringIO()256        generate([p], out)257        commands = list(lex(out))258        sh_lib_start, _ = find_command(commands, 'if', ['BUILD_SHARED_LIBS'])259        stmts = parse(iter(commands[sh_lib_start:]))[0]260        shared = { tuple(stmt[0]): (stmt[1], stmt[2]) for stmt in stmts[1] }261        assert((f'{name}_INCLUDE_DIRS',) in shared)262        includes = shared[(f'{name}_INCLUDE_DIRS',)]263        assert([] == includes[1])264        assert(1 == len(includes[0]))265        include = includes[0][0]266        assert('target_include_directories' == include[0])267        assert([name, 'INTERFACE', f'"${{{name}_INCLUDE_DIRS}}"'] == \268                                                                    include[1])269        assert((f'{name}_LDFLAGS',) in shared)270        ldflags = shared[(f'{name}_LDFLAGS',)]271        assert([] == ldflags[1])272        assert(1 == len(ldflags[0]))273        ldflag = ldflags[0][0]274        assert('target_link_libraries' == ldflag[0])275        assert([name, 'INTERFACE', f'"${{{name}_LDFLAGS}}"'] == ldflag[1])276        assert((f'{name}_CFLAGS_OTHER',) in shared)277        cflags = shared[(f'{name}_CFLAGS_OTHER',)]278        assert([] == cflags[1])279        assert(1 == len(cflags[0]))280        cflag = cflags[0][0]281        assert('target_compile_options' == cflag[0])282        assert([name, 'INTERFACE', f'"${{{name}_CFLAGS_OTHER}}"'] == cflag[1])283    def test_pkg_config_generates_static_props(self):284        name    = 'foo'285        package = 'bar'286        p = Pkg(name, package, [])287        out = StringIO()288        generate([p], out)289        commands = list(lex(out))290        sh_lib_start, _ = find_command(commands, 'if', ['BUILD_SHARED_LIBS'])291        stmts = parse(iter(commands[sh_lib_start:]))[0]292        static = { tuple(stmt[0]): (stmt[1], stmt[2]) for stmt in stmts[2] }293        assert((f'{name}_STATIC_INCLUDE_DIRS',) in static)294        includes = static[(f'{name}_STATIC_INCLUDE_DIRS',)]295        assert([] == includes[1])296        assert(1 == len(includes[0]))297        include = includes[0][0]298        assert('target_include_directories' == include[0])299        assert([name, 'INTERFACE', f'"${{{name}_STATIC_INCLUDE_DIRS}}"'] == \300                                                                    include[1])301        assert((f'{name}_STATIC_LDFLAGS',) in static)302        ldflags = static[(f'{name}_STATIC_LDFLAGS',)]303        assert([] == ldflags[1])304        assert(1 == len(ldflags[0]))...game_map.py
Source:game_map.py  
...47        y_offset = y - entity.y48        #Below complexity is necessary to find multiple keys in the dict and add them all, along with thier offsets, in correct order49        if x_offset == 1:50            if y_offset == 1:51                n_keys = find_command(options.default_keys, ('move','se'))52                keys += n_keys53                repeat = len(n_keys)54                i = 055                while i < repeat:56                    offsets.append((x_offset, y_offset))57                    i += 158            elif y_offset == 0:59                n_keys = find_command(options.default_keys, ('move','e'))60                keys += n_keys61                repeat = len(n_keys)62                i = 063                while i < repeat:64                    offsets.append((x_offset, y_offset))65                    i += 166            else:67                n_keys = find_command(options.default_keys, ('move','ne'))68                keys += n_keys69                repeat = len(n_keys)70                i = 071                while i < repeat:72                    offsets.append((x_offset, y_offset))73                    i += 174        elif x_offset == 0:75            if y_offset == 1:76                n_keys = find_command(options.default_keys, ('move','s'))77                keys += n_keys78                repeat = len(n_keys)79                i = 080                while i < repeat:81                    offsets.append((x_offset, y_offset))82                    i += 183            else:84                n_keys = find_command(options.default_keys, ('move','n'))85                keys += n_keys86                repeat = len(n_keys)87                i = 088                while i < repeat:89                    offsets.append((x_offset, y_offset))90                    i += 191        else:92            if y_offset == 1:93                n_keys = find_command(options.default_keys, ('move','sw'))94                keys += n_keys95                repeat = len(n_keys)96                i = 097                while i < repeat:98                    offsets.append((x_offset, y_offset))99                    i += 1100            elif y_offset == 0:101                n_keys = find_command(options.default_keys, ('move','w'))102                keys += n_keys103                repeat = len(n_keys)104                i = 0105                while i < repeat:106                    offsets.append((x_offset, y_offset))107                    i += 1108            else:109                n_keys = find_command(options.default_keys, ('move','nw'))110                keys += n_keys111                repeat = len(n_keys)112                i = 0113                while i < repeat:114                    offsets.append((x_offset, y_offset))115                    i += 1116    #Add spin117    n_keys = find_command(options.default_keys, ('spin','ccw'))118    keys += n_keys119    repeat = len(n_keys)120    i = 0121    while i < repeat:122        offsets.append((x_offset, y_offset))123        i += 1124    n_keys = find_command(options.default_keys, ('spin','cw'))125    keys += n_keys126    repeat = len(n_keys)127    i = 0128    while i < repeat:129        offsets.append((x_offset, y_offset))130        i += 1131    #Add strafe132    keys += find_command(options.default_keys, 'strafe')133    offsets.append((0,0))134    return keys, offsets135def command_to_offset(command) -> list:136    direction = []137    direction.extend(command.get('move'))138    y_mod = 0139    x_mod = 0140    for xy in direction:141        if xy == 'n':142            y_mod = -1143        if xy == 's':144            y_mod = 1145        if xy == 'w':146            x_mod = -1...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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!
