File: test_examples.py

package info (click to toggle)
terminaltables3 4.0.0-5
  • links: PTS, VCS
  • area: main
  • in suites: forky
  • size: 1,324 kB
  • sloc: python: 2,691; makefile: 91; sh: 11
file content (32 lines) | stat: -rw-r--r-- 702 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
"""Test example scripts."""

import os
import subprocess
import sys

import pytest

from tests import PROJECT_ROOT


@pytest.mark.parametrize("filename", map("example{}.py".format, (1, 2, 3)))
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