"Fossies" - the Fresh Open Source Software Archive

Member "http-prompt-2.1.0/tests/test_utils.py" (5 Mar 2021, 3637 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 from http_prompt import utils
    2 
    3 
    4 def test_colformat_zero_items():
    5     assert list(utils.colformat([], terminal_width=80)) == []
    6 
    7 
    8 def test_colformat_one_item():
    9     assert list(utils.colformat(['hello'], terminal_width=80)) == ['hello']
   10 
   11 
   12 def test_colformat_single_line():
   13     items = ['hello', 'world', 'foo', 'bar']
   14     assert list(utils.colformat(items, terminal_width=80)) == [
   15         'hello world foo   bar'
   16     ]
   17 
   18 
   19 def test_colformat_single_column():
   20     items = ['chap1.txt', 'chap2.txt', 'chap3.txt', 'chap4.txt',
   21              'chap5.txt', 'chap6.txt', 'chap7.txt', 'chap8.txt']
   22     assert list(utils.colformat(items, terminal_width=10)) == [
   23         'chap1.txt', 'chap2.txt', 'chap3.txt', 'chap4.txt',
   24         'chap5.txt', 'chap6.txt', 'chap7.txt', 'chap8.txt'
   25     ]
   26 
   27 
   28 def test_colformat_multi_columns_no_remainder():
   29     items = ['chap1.txt', 'chap2.txt', 'chap3.txt', 'chap4.txt',
   30              'chap5.txt', 'chap6.txt', 'chap7.txt', 'chap8.txt',
   31              'chap9.txt', 'chap10.txt', 'chap11.txt', 'chap12.txt']
   32     assert list(utils.colformat(items, terminal_width=50)) == [
   33         'chap1.txt  chap4.txt  chap7.txt  chap10.txt',
   34         'chap2.txt  chap5.txt  chap8.txt  chap11.txt',
   35         'chap3.txt  chap6.txt  chap9.txt  chap12.txt'
   36     ]
   37 
   38 
   39 def test_colformat_multi_columns_remainder_1():
   40     items = ['chap1.txt', 'chap2.txt', 'chap3.txt', 'chap4.txt',
   41              'chap5.txt', 'chap6.txt', 'chap7.txt', 'chap8.txt',
   42              'chap9.txt', 'chap10.txt', 'chap11.txt', 'chap12.txt',
   43              'chap13.txt']
   44     assert list(utils.colformat(items, terminal_width=50)) == [
   45         'chap1.txt  chap5.txt  chap9.txt  chap13.txt',
   46         'chap2.txt  chap6.txt  chap10.txt',
   47         'chap3.txt  chap7.txt  chap11.txt',
   48         'chap4.txt  chap8.txt  chap12.txt'
   49     ]
   50 
   51 
   52 def test_colformat_multi_columns_remainder_2():
   53     items = ['chap1.txt', 'chap2.txt', 'chap3.txt', 'chap4.txt',
   54              'chap5.txt', 'chap6.txt', 'chap7.txt', 'chap8.txt',
   55              'chap9.txt', 'chap10.txt', 'chap11.txt', 'chap12.txt',
   56              'chap13.txt', 'chap14.txt']
   57     assert list(utils.colformat(items, terminal_width=50)) == [
   58         'chap1.txt  chap5.txt  chap9.txt  chap13.txt',
   59         'chap2.txt  chap6.txt  chap10.txt chap14.txt',
   60         'chap3.txt  chap7.txt  chap11.txt',
   61         'chap4.txt  chap8.txt  chap12.txt'
   62     ]
   63 
   64 
   65 def test_colformat_wider_than_terminal():
   66     items = ['a very long long name', '1111 2222 3333 4444 5555']
   67     assert list(utils.colformat(items, terminal_width=10)) == [
   68         'a very long long name',
   69         '1111 2222 3333 4444 5555'
   70     ]
   71 
   72 
   73 def test_colformat_long_short_mixed():
   74     items = ['a', '1122334455667788', 'hello world', 'foo bar',
   75              'b', '8877665544332211', 'abcd', 'yeah']
   76     assert list(utils.colformat(items, terminal_width=50)) == [
   77         'a                foo bar          abcd',
   78         '1122334455667788 b                yeah',
   79         'hello world      8877665544332211'
   80     ]
   81 
   82 
   83 def test_colformat_github_top_endpoints():
   84     items = ['emojis', 'events', 'feeds', 'gists', 'gitignore', 'issues',
   85              'legacy', 'markdown', 'meta', 'networks', 'notifications',
   86              'orgs', 'rate_limit', 'repos', 'repositories', 'search',
   87              'teams', 'user', 'users']
   88     assert list(utils.colformat(items, terminal_width=136)) == [
   89         'emojis        gists         legacy        networks      rate_limit''    search        users',  # noqa
   90         'events        gitignore     markdown      notifications repos         teams',  # noqa
   91         'feeds         issues        meta          orgs          repositories  user'  # noqa
   92     ]