forked from robotframework/robotframework
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_encodingsniffer.py
More file actions
54 lines (38 loc) · 1.6 KB
/
test_encodingsniffer.py
File metadata and controls
54 lines (38 loc) · 1.6 KB
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import unittest
import sys
from robot.utils.asserts import assert_equal, assert_not_none
from robot.utils.encodingsniffer import get_console_encoding
from robot.utils import PY3, WINDOWS
class StreamStub(object):
def __init__(self, encoding):
self.encoding = encoding
# We don't look at streams on Windows with Python 3. Cannot run tests either.
BASE = unittest.TestCase if not (WINDOWS and PY3) else object
class TestGetConsoleEncodingFromStandardStreams(BASE):
def setUp(self):
self._orig_streams = sys.__stdout__, sys.__stderr__, sys.__stdin__
def tearDown(self):
sys.__stdout__, sys.__stderr__, sys.__stdin__ = self._orig_streams
def test_valid_encoding(self):
sys.__stdout__ = StreamStub('ASCII')
assert_equal(get_console_encoding(), 'ASCII')
def test_invalid_encoding(self):
sys.__stdout__ = StreamStub('invalid')
sys.__stderr__ = StreamStub('ascII')
assert_equal(get_console_encoding(), 'ascII')
def test_no_encoding(self):
sys.__stdout__ = object()
sys.__stderr__ = object()
sys.__stdin__ = StreamStub('ascii')
assert_equal(get_console_encoding(), 'ascii')
sys.__stdin__ = object()
assert_not_none(get_console_encoding())
def test_none_encoding(self):
sys.__stdout__ = StreamStub(None)
sys.__stderr__ = StreamStub(None)
sys.__stdin__ = StreamStub('ascii')
assert_equal(get_console_encoding(), 'ascii')
sys.__stdin__ = StreamStub(None)
assert_not_none(get_console_encoding())
if __name__ == '__main__':
unittest.main()