Best Python code snippet using autotest_python
main.py
Source:main.py  
1# -*- mode: python; coding: utf-8 -*-2#3# Copyright (C) 2017 <contact@redhat.com>4#5# Author: Loic Dachary <loic@dachary.org>6#7# This program is free software: you can redistribute it and/or modify8# it under the terms of the GNU General Public License as published by9# the Free Software Foundation, either version 3 of the License, or10# (at your option) any later version.11#12# This program is distributed in the hope that it will be useful,13# but WITHOUT ANY WARRANTY; without even the implied warranty of14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the15# GNU General Public License for more details.16#17# You should have received a copy of the GNU General Public License18# along with this program.  If not, see <http://www.gnu.org/licenses/>.19#20import argparse21import collections22import logging23import textwrap24from crush import Crush25from crush import analyze26from crush import compare27from crush import optimize28log = logging.getLogger('crush')29class Main(object):30    def __init__(self):31        self.create_parser()32        if self.parser.get_default('backward_compatibility') is None:33            self.parser.set_defaults(backward_compatibility=False)34        self.parser.add_argument(35            '-v', '--verbose',36            action='store_true', default=None,37            help='be more verbose',38        )39        self.parser.add_argument(40            '--debug',41            action='store_true', default=None,42            help='debugging output, very verbose',43        )44        self.subparsers = self.parser.add_subparsers(45            title='subcommands',46            description='valid subcommands',47            help='sub-command -h',48        )49        analyze.Analyze.set_parser(self.subparsers, self.hook_analyze_args)50        compare.Compare.set_parser(self.subparsers, self.hook_compare_args)51        optimize.Optimize.set_parser(self.subparsers, self.hook_optimize_args)52    def create_parser(self):53        self.parser = argparse.ArgumentParser(54            formatter_class=argparse.RawDescriptionHelpFormatter,55            description=textwrap.dedent("""\56            A library to control placement in a hierarchy57            """))58    def __getstate__(self):59        return (self.argv,)60    def __setstate__(self, state):61        self.__init__()62        self.parse(state[0])63    def clone(self):64        return Main()65    def parse(self, argv):66        self.argv = argv67        self.args = self.parser.parse_args(argv)68        if self.args.debug:69            level = logging.DEBUG70            format = '%(asctime)s %(funcName)20s %(message)s'71        elif self.args.verbose:72            level = logging.INFO73            format = '%(asctime)s %(funcName)20s %(message)s'74        else:75            level = logging.WARNING76            format = '%(asctime)s %(message)s'77        if log.getEffectiveLevel() == 0 or log.getEffectiveLevel() > level:78            log.setLevel(level)79        logging.basicConfig(format=format)80    @staticmethod81    def get_trimmed_argv(to_parser, args):82        options = []83        positionals = []84        dest2option = {}85        known_dests = []86        for action in to_parser._actions:87            option = list(filter(lambda o: o in to_parser._option_string_actions,88                                 action.option_strings))89            if len(option) > 0:90                dest2option[action.dest] = option[0]91            known_dests.append(action.dest)92        v = collections.OrderedDict(sorted(vars(args).items(),93                                           key=lambda t: t[0]))94        for (key, value) in v.items():95            log.debug('get_trimmed_argv: checking ' +96                      str(key) + "=" + str(value))97            if key not in known_dests:98                log.debug('get_trimmed_argv: skip unknown ' + str(key))99                continue100            if key in dest2option:101                option = dest2option[key]102                action = to_parser._option_string_actions[option]103                if value != action.default:104                    if action.nargs is None or action.nargs == 1:105                        options.extend([option, str(value)])106                    elif action.nargs == 0:107                        options.append(option)108            else:109                log.debug('get_trimmed_argv: positional ' +110                          str(key) + "=" + str(value))111                positionals.extend(value)112        return options + positionals113    def constructor(self, argv):114        self.parse(argv)115        return self.args.func(self.args, self)116    def main(self, argv):117        return self.constructor(argv).run()118    def hook_analyze_args(self, parser):119        pass120    def hook_analyze_pre_sanity_check_args(self, args):121        if not args.crushmap:122            raise Exception("missing --crushmap")123    def hook_analyze_post_sanity_check_args(self, args):124        if not args.rule:125            raise Exception("missing --rule")126    def hook_compare_args(self, parser):127        pass128    def hook_compare_pre_sanity_check_args(self, args):129        if not args.origin:130            raise Exception("missing --origin")131        if not args.destination:132            raise Exception("missing --destination")133    def hook_compare_post_sanity_check_args(self, args):134        if not args.rule:135            raise Exception("missing --rule")136    def hook_optimize_args(self, parser):137        pass138    def hook_optimize_pre_sanity_check_args(self, args):139        self.hook_analyze_pre_sanity_check_args(args)140        if self.args.with_forecast is False and not self.args.step:141            raise Exception("--no-forecast is only valid with --step")142        if not self.args.out_path:143            raise Exception("missing --out-path")144    def hook_optimize_post_sanity_check_args(self, args):145        self.hook_analyze_post_sanity_check_args(args)146        if not self.args.choose_args:147            raise Exception("missing --choose-args")148    def hook_create_values(self):149        values = range(0, self.args.values_count)150        return dict(zip(values, values))151    def value_name(self):152        return 'objects'153    def convert_to_crushmap(self, crushmap):154        c = Crush(verbose=self.args.debug,155                  backward_compatibility=self.args.backward_compatibility)156        c.parse(crushmap)157        return c.get_crushmap()158    def crushmap_to_file(self, crushmap):159        c = Crush(verbose=self.args.debug,160                  backward_compatibility=self.args.backward_compatibility)161        c.parse(crushmap)...common.py
Source:common.py  
1"""Common testing helpers & data"""2from flatdata.lib.errors import MissingResourceError3INSTANCE_TEST_SCHEMA = """4namespace backward_compatibility {5    struct SignedStruct {6        a : i16 : 5;7        b : u32 : 32;8        c : i32 : 7;9        d : u32 : 32;10    }11    archive Archive {12        resource: SignedStruct;13    }14}15"""16RESOURCE_PAYLOAD = (17    b"\x0a\x00\x00\x00\x00\x00\x00\x00"  # size of payload in bytes18    b"\xff\xac\x68\x24\x00\x0b\x00\x00"  # Payload19    b"\x00\x00"  # Payload20    b"\x00\x00\x00\x00\x00\x00\x00\x00"  # Padding21)22ARCHIVE_SIGNATURE_PAYLOAD = (23    b"\x00\x00\x00\x00\x00\x00\x00\x00"24    b"\x00\x00\x00\x00\x00\x00\x00\x00"25)26VECTOR_TEST_SCHEMA = """27namespace backward_compatibility {28    struct SignedStruct {29        a : i16 : 5;30        b : u32 : 32;31        c : i32 : 7;32        d : u32 : 32;33    }34    archive Archive {35        resource: vector< SignedStruct >;36    }37}38"""39RESOURCE_VECTOR_PAYLOAD = (40    b"\x14\x00\x00\x00\x00\x00\x00\x00"  # Payload size in bytes41    b"\xff\xac\x68\x24\x00\x0b\x00\x00"  # Payload42    b"\x00\x00\xff\xac\x68\x24\x00\x0b"  # Payload43    b"\x00\x00\x00\x00"  # Payload44    b"\x00\x00\x00\x00\x00\x00\x00\x00"  # Padding45)46MULTIVECTOR_TEST_SCHEMA = """47namespace backward_compatibility {48    struct SimpleStruct {49        a : u32 : 32;50        b : u32 : 32;51    }52    struct SignedStruct {53        a : i16 : 5;54        b : u32 : 32;55        c : i32 : 7;56        d : u32 : 32;57    }58    archive Archive {59        resource: multivector< 33, SimpleStruct, SignedStruct >;60    }61}62"""63MULTIVECTOR_RESOURCE_DATA = (64    b"\x31\x00\x00\x00\x00\x00\x00\x00"  # Payload size in bytes65    b"\x01\xff\xac\x68\x24\x00\x0b\x00\x00\x00\x00"  # Payload66    b"\x00\xff\xff\xff\xff\xef\xbe\xad\xde"  # Payload67    b"\x00\xff\xff\xff\xff\xef\xbe\xad\xde"  # Payload68    b"\x01\xff\xac\x68\x24\x00\x0b\x00\x00\x00\x00"  # Payload69    b"\x00\xff\xff\xff\xff\xef\xbe\xad\xde"  # Payload70    b"\x00\x00\x00\x00\x00\x00\x00\x00"  # Padding71)72MULTIVECTOR_RESOURCE_INDEX = (73    b"\x19\x00\x00\x00\x00\x00\x00\x00"  # Index size in bytes74    b"\x00\x00\x00\x00\x00"  # Data pointer 175    b"\x14\x00\x00\x00\x00"  # Data pointer 276    b"\x14\x00\x00\x00\x00"  # Data pointer 377    b"\x28\x00\x00\x00\x00"  # Data pointer 478    b"\x31\x00\x00\x00\x00"  # Sentinel (end of data 4)79    b"\x00\x00\x00\x00\x00\x00\x00\x00"  # Padding80)81RAW_DATA_TEST_SCHEMA = """82namespace backward_compatibility {83    archive Archive {84        resource: raw_data;85    }86}87"""88RAW_DATA_RESOURCE_DATA = (89    b"\x05\x00\x00\x00\x00\x00\x00\x00"  # Payload size in bytes90    b"\xff\xef\xbe\xad\xde"  # Payload91    b"\x00\x00\x00\x00\x00\x00\x00\x00"  # Padding92)93# pylint: disable=too-few-public-methods,missing-docstring94class DictResourceStorage:95    """96    Resource storage based on dict.97    """98    def __init__(self, data=None):99        self.data = data if data is not None else dict()100    def get(self, key, is_optional=False):101        if key not in self.data:102            if not is_optional:103                raise MissingResourceError(key)104            else:105                return None106        value = self.data[key]107        if isinstance(value, bytes):108            class _Monkey(bytes):109                def read(self):110                    return self111            return _Monkey(value)112        assert isinstance(value, dict)...setup.py
Source:setup.py  
1from pathlib import Path2import setuptools3path = Path(__file__)4setup_requires = ["numpy", "pytest-runner", "pytest-pylint"]5install_requires = [6    "click",7]8test_require = ["pytest-cov", "pytest-html", "pytest", "click", "pylint"]9setuptools.setup(10    name="kgcn_torch",11    version="0.1.0",12    python_requires=">3.5",13    author=["Ryosuke Kojima","Koji Ono"],14    author_email=["kojima.ryosuke.8e@kyoto-u.ac.jp", "kbu94982@gmail.com"],15    description="graph convolutional network library",16    long_description_content_type="text/markdown",17    long_description=(path.parent / "README.md").open(encoding="utf-8").read(),18    packages=setuptools.find_packages(),19    install_requires=install_requires,20    setup_requires=setup_requires,21    url="https://github.com/clinfo/kGCN_torch",22    tests_require=test_require,23    extras_require={"docs": ["sphinx >= 1.4", "sphinx_rtd_theme"]},24    entry_points={25        "console_scripts": [26            "kgcnt = kgcn_torch.backward_compatibility.gcn:main",27            "kgcnt-chem = kgcn_torch.backward_compatibility.chem:main",28            "kgcnt-cv-splitter = kgcn_torch.backward_compatibility.cv_splitter:main",29            "kgcnt-opt = kgcn_torch.backward_compatibility.opt:main",30            "kgcnt-gen = kgcn_torch.backward_compatibility.gen:main",31            "kgcnt-sparse = kgcn_torch.backward_compatibility.task_sparse_gcn:main",32        ],33    },34    classifiers=[35        "Programming Language :: Python",36        "Programming Language :: Python :: 3.6",37        "Programming Language :: Python :: 3.7",38        "Programming Language :: Python :: 3.8",39        "License :: OSI Approved :: MIT License",40        "Operating System :: OS Independent",41    ],...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!!
