Best Python code snippet using autotest_python
logging_manager_test.py
Source:logging_manager_test.py  
...128        manager.redirect_to_stream(self._log1)129        self._say(3)130        manager.tee_redirect_to_stream(self._log2)131        self._say(4)132        manager.undo_redirect()133        self._say(5)134        manager.undo_redirect()135        self._say(6)136        manager.stop_logging()137        self._say(7)138    def _grab_fd_info(self):139        command = 'ls -l /proc/%s/fd' % os.getpid()140        proc = subprocess.Popen(command.split(), shell=True,141                                stdout=subprocess.PIPE)142        return proc.communicate()[0]143    def _compare_logs(self, log_buffer, expected_text):144        actual_lines = log_buffer.getvalue().splitlines()145        expected_lines = expected_text.splitlines()146        if self._real_system_calls:147            # because of the many interacting processes, we can't ensure perfect148            # interleaving.  so compare sets of lines rather than ordered lines.149            actual_lines = set(actual_lines)150            expected_lines = set(expected_lines)151        self.assertEquals(actual_lines, expected_lines)152    def _check_results(self):153        # ensure our stdout was restored154        self.assertEquals(self.stdout, self._original_stdout)155        if self._real_system_calls:156            # ensure FDs were left in their original state157            self.assertEquals(self._grab_fd_info(), self._fd_info)158        self._compare_logs(self.stdout, _EXPECTED_STDOUT)159        self._compare_logs(self._log1, _EXPECTED_LOG1)160        self._compare_logs(self._log2, _EXPECTED_LOG2)161    def test_logging_manager(self):162        self._run_test(logging_manager.LoggingManager)163        self._check_results()164    def test_fd_redirection_logging_manager(self):165        self._real_system_calls = True166        self._fd_info = self._grab_fd_info()167        self._run_test(logging_manager.FdRedirectionLoggingManager)168        self._check_results()169    def test_tee_redirect_debug_dir(self):170        manager = self._setup_manager()171        manager.start_logging()172        manager.tee_redirect_debug_dir('/fake/dir', tag='mytag')173        print >>self.stdout, 'hello'174        manager.undo_redirect()175        print >>self.stdout, 'goodbye'176        manager.stop_logging()177        self._compare_logs(self.stdout,178                           'INFO: mytag : hello\nINFO: goodbye')179        self._compare_logs(self._config_object.log, 'hello\n')180class MonkeyPatchTestCase(unittest.TestCase):181    def setUp(self):182        filename = os.path.split(__file__)[1]183        if filename.endswith('.pyc'):184            filename = filename[:-1]185        self.expected_filename = filename186    def check_filename(self, filename, expected=None):187        if expected is None:188            expected = [self.expected_filename]...url_rewriter_async.py
Source:url_rewriter_async.py  
...27        decode += fallback28    send_answer(f'{ch} {decode}\n')29async def get_next_element():30    return q.get()31async def undo_redirect(main, url, domain):32    return main.undo_redirect(url, domain)33async def do_redirect(main, url, domain):34    return main.do_redirect(url, domain)35async def do_work(main, loop):36    while True:37        try:38            item = await get_next_element()39            if not item:40                break41            clean_line = item.strip()42            if not clean_line:43                q.task_done()44                continue45            data = dict(zip(label, clean_line.split(b' ')))46            scheme, domain, path = main.split_url(data['URL'])47            channel = data['CHANNEL'].decode(generic_encoding)48            if main.get_suffix() in domain:49                new_domain = await undo_redirect(main, data['URL'], domain)50                if new_domain:51                    await send_rewrite(channel, new_domain)52                    q.task_done()53                    continue54                elif b'/login' in path:55                    # LATER checagem de usuario/senha aqui?56                    #   negativo, o ponto correto eh na57                    #   liberacao_ip sem a senha correta n58                    #   deveria nem chegar nesse ponto!59                    temp = main.extract_url_from_path(path, scheme)60                    (ok, new_domain) = await do_redirect(main, temp, domain)61                    if new_domain:62                        await send_redirect(channel, new_domain)63                        q.task_done()...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!!
