File: test_utils.py

package info (click to toggle)
awscli 2.31.35-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 156,692 kB
  • sloc: python: 213,816; xml: 14,082; makefile: 189; sh: 178; javascript: 8
file content (26 lines) | stat: -rw-r--r-- 748 bytes parent folder | download
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
import codecs
import os
import shutil
import tempfile

from awscli.testutils import unittest
from awscli.utils import write_exception


class TestWriteException(unittest.TestCase):
    def setUp(self):
        self.tempdir = tempfile.mkdtemp()
        self.outfile = os.path.join(self.tempdir, 'stdout')

    def tearDown(self):
        shutil.rmtree(self.tempdir)

    def test_write_exception(self):
        error_message = "Some error message."
        ex = Exception(error_message)
        with codecs.open(self.outfile, 'w+', encoding='utf-8') as outfile:
            write_exception(ex, outfile)
            outfile.seek(0)

            expected_output = "\n%s\n" % error_message
            self.assertEqual(outfile.read(), expected_output)