File: test_pipe.py

package info (click to toggle)
pygopherd 3.0.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,928 kB
  • sloc: python: 6,534; makefile: 40; sh: 28
file content (37 lines) | stat: -rw-r--r-- 1,193 bytes parent folder | download | duplicates (2)
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
33
34
35
36
37
import os
import subprocess
import tempfile
import unittest

from pygopherd import testutil


class PipeTestCase(unittest.TestCase):
    def setUp(self):
        self.config = testutil.get_config()
        self.root = self.config.get("pygopherd", "root")
        self.testdata = self.root + "/pygopherd/pipetestdata"
        self.testprog = self.root + "/pygopherd/pipetest.sh"

    def testWorkingPipe(self):
        with tempfile.TemporaryFile(mode="w+") as outputfd:
            with open(self.testdata, "r") as inputfd:
                retval = subprocess.run(
                    [self.testprog],
                    stdin=inputfd,
                    stdout=outputfd,
                    errors="surrogateescape",
                )
                outputfd.seek(0)

                self.assertEqual(
                    outputfd.read(),
                    "Starting\nGot [Word1]\nGot [Word2]\nGot [Word3]\nEnding\n",
                )

            self.assertTrue(os.WIFEXITED(retval.returncode), "WIFEXITED was not true")
            self.assertEqual(os.WEXITSTATUS(retval.returncode), 0)
            self.assertEqual(retval.returncode, 0)

    def testFailingPipe(self):
        pass