"Fossies" - the Fresh Open Source Software Archive

Member "http-prompt-2.1.0/tests/test_interaction.py" (5 Mar 2021, 2286 Bytes) of package /linux/www/http-prompt-2.1.0.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Python source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file.

    1 import os
    2 import sys
    3 
    4 import pexpect
    5 import pytest
    6 
    7 from .base import TempAppDirTestCase
    8 from .utils import get_http_prompt_path
    9 from http_prompt import config
   10 
   11 
   12 class TestInteraction(TempAppDirTestCase):
   13 
   14     def setUp(self):
   15         super(TestInteraction, self).setUp()
   16 
   17         # Use temporary directory as user config home.
   18         # Will restore it in tearDown().
   19         self.orig_config_home = os.getenv('XDG_CONFIG_HOME')
   20         os.environ['XDG_CONFIG_HOME'] = self.temp_dir
   21 
   22         # Make sure pexpect uses the same terminal environment
   23         self.orig_term = os.getenv('TERM')
   24         os.environ['TERM'] = 'screen-256color'
   25 
   26     def tearDown(self):
   27         super(TestInteraction, self).tearDown()
   28 
   29         os.environ['XDG_CONFIG_HOME'] = self.orig_config_home
   30 
   31         if self.orig_term:
   32             os.environ['TERM'] = self.orig_term
   33         else:
   34             os.environ.pop('TERM', None)
   35 
   36     def write_config(self, content):
   37         config_path = config.get_user_config_path()
   38         with open(config_path, 'a') as f:
   39             f.write(content)
   40 
   41     @pytest.mark.skipif(sys.platform == 'win32',
   42                         reason="pexpect doesn't work well on Windows")
   43     @pytest.mark.slow
   44     def test_interaction(self):
   45         bin_path = get_http_prompt_path()
   46         child = pexpect.spawn(bin_path, env=os.environ)
   47 
   48         # TODO: Test more interaction
   49 
   50         child.sendline('exit')
   51         child.expect_exact('Goodbye!', timeout=20)
   52         child.close()
   53 
   54     @pytest.mark.skipif(sys.platform == 'win32',
   55                         reason="pexpect doesn't work well on Windows")
   56     @pytest.mark.slow
   57     def test_vi_mode(self):
   58         self.write_config('vi = True\n')
   59 
   60         bin_path = get_http_prompt_path()
   61         child = pexpect.spawn(bin_path, env=os.environ)
   62 
   63         child.expect_exact('http://localhost:8000> ')
   64 
   65         # Enter 'htpie', switch to command mode (ESC),
   66         # move two chars left (hh), and insert (i) a 't'
   67         child.send('htpie')
   68         child.send('\x1b')
   69         child.sendline('hhit')
   70 
   71         child.expect_exact('http http://localhost:8000')
   72 
   73         # Enter 'exit'
   74         child.send('\x1b')
   75         child.send('i')
   76         child.sendline('exit')
   77 
   78         child.expect_exact('Goodbye!', timeout=20)
   79         child.close()