Best Python code snippet using Testify_python
tar.py
Source:tar.py  
...103        # limited to the container104        self.namespace.execns(tar.extractall, self.dest_dir)105    def pre_setup(self):106        raise NotImplementedError()107    def parent_setup(self):108        raise NotImplementedError()109    def child_setup(self):110        """111        :rtype : file112        """113        raise NotImplementedError()114    def run(self):115        self.pre_setup()116        pid = os.fork()117        if pid:118            try:119                self.parent_setup()120            finally:121                _, ret = os.waitpid(pid, 0)122                exitcode = ret >> 8123                exitsig = ret & 0x7f124                if exitsig:125                    raise RuntimeError('Extraction caught signal {0}'.format(exitsig))126                elif exitcode:127                    raise RuntimeError('Extraction exited with status {0}'.format(exitcode))128        else:129            fp = self.child_setup()130            self.extract_from_fp(fp)131class ExtractTarFile(ExtractTarBase):132    # TODO: support xz archives via subprocess.Popen piping to tar inside133    def __init__(self, namespace, dest_dir, archive_path):134        super(ExtractTarFile, self).__init__(namespace, dest_dir)135        self.archive_path = archive_path136    def run(self):137        logger.info('Extracting {0} to {1} inside container'.format(self.archive_path, self.dest_dir))138        super(ExtractTarFile, self).run()139    def pre_setup(self):140        pass141    def parent_setup(self):142        pass143    def child_setup(self):144        return open(self.archive_path)145class ExtractNamespacedTar(ExtractTarBase):146    def __init__(self, namespace, dest_dir, src_dir):147        super(ExtractNamespacedTar, self).__init__(namespace, dest_dir)148        self.src_dir = src_dir149        self.rpipe = None150        self.wpipe = None151    def pre_setup(self):152        self.rpipe, self.wpipe = os.pipe()153    def src_namespace(self):154        fs = FilesystemNamespace(self.src_dir)155        return ContainerNamespace(fs, self.namespace.user_namespace)156    def child_setup(self):157        os.close(self.wpipe)158        return os.fdopen(self.rpipe, 'r')159    def build_tar_archive(self, archive):160        raise NotImplementedError()161    def parent_setup(self):162        os.close(self.rpipe)163        archive = os.fdopen(self.wpipe, 'w')164        try:165            self.build_tar_archive(archive)166        finally:167            archive.close()168class UnpackArchive(ExtractNamespacedTar):169    def __init__(self, namespace, dest_dir, src_dir, archive_path):170        super(UnpackArchive, self).__init__(namespace, dest_dir, src_dir)171        self.archive_path = archive_path172    def build_tar_archive(self, archive):173        fmt = detect_tar_format(self.archive_path)174        tar_pipe = archive175        xz = None...utils.py
Source:utils.py  
1import pytest2from pydantic import ValidationError3def parent_setup(self):4    if self.parent:5        print("Parent:", self.parent.example_data)6        self.correct_data = map(lambda x: {**self.parent.example_data, **x}, self.correct_data)7        self.wrong_data = map(lambda x: {**self.parent.example_data, **x}, self.wrong_data)8        self.irregular_data = map(lambda x: {**self.parent.example_data, **x}, self.irregular_data)9class BaseModelTest:10    schema = None11    parent = None12    example_data = {}13    correct_data = []14    wrong_data = []15    irregular_data = []16    def test_validate(self):17        parent_setup(self)18        for correct in [*self.correct_data, self.example_data]:19            print("Correct:", correct)20            print("Parsed:", self.schema(**correct))21            assert self.schema(**correct) == correct22        for wrong in self.wrong_data:23            with pytest.raises(ValidationError):24                print("Wrong:", wrong)25                print("Parsed:", self.schema(**wrong))26    def test_parsing(self):27        parent_setup(self)28        for irregular in self.irregular_data:29            print("Irregular:", irregular)30            print("Parsed:", self.schema(**irregular))...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!!
