File: test_utils.py

package info (click to toggle)
importlab 0.8.1-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 292 kB
  • sloc: python: 1,761; sh: 14; makefile: 6
file content (31 lines) | stat: -rw-r--r-- 837 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
"""Tests for utils.py."""

import sys
import tempfile
import unittest

from importlab import utils


class TestUtils(unittest.TestCase):
    """Tests for utils."""

    def test_strip_suffix(self):
        a = 'foo bar bar'
        self.assertEqual(a, utils.strip_suffix(a, 'hello'))
        self.assertEqual('foo bar ', utils.strip_suffix(a, 'bar'))
        self.assertEqual(a, utils.strip_suffix(a, 'hbar'))

    def test_run_py_file(self):
        version = sys.version_info[:2]
        with tempfile.NamedTemporaryFile(mode='w') as f:
            f.write('print("test")')
            f.flush()
            ret, stdout, stderr = utils.run_py_file(version, f.name)
        self.assertFalse(ret)
        self.assertEqual(stdout.strip().decode(), 'test')
        self.assertFalse(stderr)


if __name__ == "__main__":
    unittest.main()