def test_windows_screenshot(tmpdir, mode):
    """Test function on Windows in a new console window. Take a screenshot to verify it works.

    :param tmpdir: pytest fixture.
    :param str mode: Scenario to test for.
    """
    script = tmpdir.join('script.py')
    command = [sys.executable, str(script)]
    change_title = tmpdir.join('change_title')
    screenshot = PROJECT_ROOT.join('test_terminal_io.png')
    if screenshot.check():
        screenshot.remove()

    # Determine title.
    if mode == 'ascii':
        title = "'test ASCII test'"
    elif mode == 'unicode':
        title = u"u'test 世界你好蓝色 test'"
    else:
        title = "b'test ASCII test'"

    # Generate script.
    script_template = dedent(u"""\
    # coding: utf-8
    from __future__ import print_function
    import os, time
    from terminaltables.terminal_io import set_terminal_title
    stop_after = time.time() + 20

    print('Waiting for FindWindowA() in RunNewConsole.__enter__()...')
    while not os.path.exists(r'{change_title}') and time.time() < stop_after:
        time.sleep(0.5)
    assert set_terminal_title({title}) is True

    print('Waiting for screenshot_until_match()...')
    while not os.path.exists(r'{screenshot}') and time.time() < stop_after:
        time.sleep(0.5)
    """)
    script_contents = script_template.format(change_title=str(change_title),
                                             title=title,
                                             screenshot=str(screenshot))
    script.write(script_contents.encode('utf-8'), mode='wb')

    # Setup expected.
    if mode == 'unicode':
        sub_images = [str(p) for p in HERE.listdir('sub_title_cjk_*.bmp')]
    else:
        sub_images = [str(p) for p in HERE.listdir('sub_title_ascii_*.bmp')]
    assert sub_images

    # Run.
    with RunNewConsole(command) as gen:
        change_title.ensure(file=True)  # Touch file.
        screenshot_until_match(str(screenshot), 15, sub_images, 1, gen)
def test_windows_screenshot(tmpdir, mode):
    """Test function on Windows in a new console window. Take a screenshot to verify it works.

    :param tmpdir: pytest fixture.
    :param str mode: Scenario to test for.
    """
    script = tmpdir.join('script.py')
    command = [sys.executable, str(script)]
    change_title = tmpdir.join('change_title')
    screenshot = PROJECT_ROOT.join('test_terminal_io_{0}.png'.format(mode))
    if screenshot.check():
        screenshot.remove()

    # Determine title.
    if mode == 'ascii':
        title = "'test ASCII test'"
    elif mode == 'unicode':
        title = u"u'test 世界你好蓝色 test'"
    else:
        title = "b'test ASCII test'"

    # Generate script.
    script_template = dedent(u"""\
    # coding: utf-8
    from __future__ import print_function
    import os, time
    from terminaltables.terminal_io import set_terminal_title
    stop_after = time.time() + 20

    print('Waiting for FindWindowA() in RunNewConsole.__enter__()...')
    while not os.path.exists(r'{change_title}') and time.time() < stop_after:
        time.sleep(0.5)
    assert set_terminal_title({title}) is True

    print('Waiting for screenshot_until_match()...')
    while not os.path.exists(r'{screenshot}') and time.time() < stop_after:
        time.sleep(0.5)
    """)
    script_contents = script_template.format(change_title=str(change_title), title=title, screenshot=str(screenshot))
    script.write(script_contents.encode('utf-8'), mode='wb')

    # Setup expected.
    if mode == 'unicode':
        sub_images = [str(p) for p in HERE.listdir('sub_title_cjk_*.bmp')]
    else:
        sub_images = [str(p) for p in HERE.listdir('sub_title_ascii_*.bmp')]
    assert sub_images

    # Run.
    with RunNewConsole(command) as gen:
        change_title.ensure(file=True)  # Touch file.
        screenshot_until_match(str(screenshot), 15, sub_images, 1, gen)
Example #3
0
def test(filename):
    """Test with subprocess.

    :param str filename: Example script filename to run.
    """
    command = [sys.executable, str(PROJECT_ROOT.join(filename))]
    env = dict(os.environ, PYTHONIOENCODING='utf-8')

    # Run.
    proc = subprocess.Popen(command, env=env, stderr=subprocess.STDOUT, stdout=subprocess.PIPE)
    output = proc.communicate()[0]

    # Verify.
    try:
        assert proc.poll() == 0
    except AssertionError:
        print(output)
        raise
def test(suffix):
    """Test with subprocess.

    :param int suffix: Numerical suffix of file name to test.
    """
    command = [sys.executable, str(PROJECT_ROOT.join('example{0}.py'.format(suffix)))]
    env = dict(os.environ, PYTHONIOENCODING='utf-8')

    # Run.
    proc = subprocess.Popen(command, env=env, stderr=subprocess.STDOUT, stdout=subprocess.PIPE)
    output = proc.communicate()[0]

    # Verify.
    try:
        assert proc.poll() == 0
    except AssertionError:
        print(output)
        raise
def test_windows_screenshot(tmpdir):
    """Test on Windows in a new console window. Take a screenshot to verify it works.

    :param tmpdir: pytest fixture.
    """
    script = tmpdir.join("script.py")
    command = [sys.executable, str(script)]
    screenshot = PROJECT_ROOT.join("test_double_table.png")
    if screenshot.check():
        screenshot.remove()

    # Generate script.
    script_template = dedent(
        u"""\
    from __future__ import print_function
    import os, time
    from colorclass import Color, Windows
    from terminaltables import DoubleTable
    Windows.enable(auto_colors=True)
    stop_after = time.time() + 20

    table_data = [
        [Color('{b}Name{/b}'), Color('{b}Color{/b}'), Color('{b}Misc{/b}')],
        ['Avocado', Color('{autogreen}green{/fg}'), 100],
        ['Tomato', Color('{autored}red{/fg}'), 0.5],
        ['Lettuce', Color('{autogreen}green{/fg}'), None],
    ]
    print(DoubleTable(table_data).table)

    print('Waiting for screenshot_until_match()...')
    while not os.path.exists(r'%s') and time.time() < stop_after:
        time.sleep(0.5)
    """
    )
    script_contents = script_template % str(screenshot)
    script.write(script_contents.encode("utf-8"), mode="wb")

    # Setup expected.
    sub_images = [str(p) for p in HERE.listdir("sub_double_*.bmp")]
    assert sub_images

    # Run.
    with RunNewConsole(command) as gen:
        screenshot_until_match(str(screenshot), 15, sub_images, 1, gen)
def test_windows_screenshot(tmpdir):
    """Test on Windows in a new console window. Take a screenshot to verify it works.

    :param tmpdir: pytest fixture.
    """
    script = tmpdir.join('script.py')
    command = [sys.executable, str(script)]
    screenshot = PROJECT_ROOT.join('test_double_table.png')
    if screenshot.check():
        screenshot.remove()

    # Generate script.
    script_template = dedent(u"""\
    from __future__ import print_function
    import os, time
    from colorclass import Color, Windows
    from terminaltables import DoubleTable
    Windows.enable(auto_colors=True)
    stop_after = time.time() + 20

    table_data = [
        [Color('{b}Name{/b}'), Color('{b}Color{/b}'), Color('{b}Misc{/b}')],
        ['Avocado', Color('{autogreen}green{/fg}'), 100],
        ['Tomato', Color('{autored}red{/fg}'), 0.5],
        ['Lettuce', Color('{autogreen}green{/fg}'), None],
    ]
    print(DoubleTable(table_data).table)

    print('Waiting for screenshot_until_match()...')
    while not os.path.exists(r'%s') and time.time() < stop_after:
        time.sleep(0.5)
    """)
    script_contents = script_template % str(screenshot)
    script.write(script_contents.encode('utf-8'), mode='wb')

    # Setup expected.
    sub_images = [str(p) for p in HERE.listdir('sub_double_*.bmp')]
    assert sub_images

    # Run.
    with RunNewConsole(command) as gen:
        screenshot_until_match(str(screenshot), 15, sub_images, 1, gen)
Example #7
0
def test(filename):
    """Test with subprocess.

    :param str filename: Example script filename to run.
    """
    command = [sys.executable, str(PROJECT_ROOT.join(filename))]
    env = dict(os.environ, PYTHONIOENCODING='utf-8')

    # Run.
    proc = subprocess.Popen(command,
                            env=env,
                            stderr=subprocess.STDOUT,
                            stdout=subprocess.PIPE)
    output = proc.communicate()[0]

    # Verify.
    try:
        assert proc.poll() == 0
    except AssertionError:
        print(output)
        raise
Example #8
0
def test(suffix):
    """Test with subprocess.

    :param int suffix: Numerical suffix of file name to test.
    """
    command = [
        sys.executable,
        str(PROJECT_ROOT.join('example{0}.py'.format(suffix)))
    ]
    env = dict(os.environ, PYTHONIOENCODING='utf-8')

    # Run.
    proc = subprocess.Popen(command,
                            env=env,
                            stderr=subprocess.STDOUT,
                            stdout=subprocess.PIPE)
    output = proc.communicate()[0]

    # Verify.
    try:
        assert proc.poll() == 0
    except AssertionError:
        print(output)
        raise