#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""
test_shut
----------------------------------

Tests for `shut` module.
"""

import sys
import unittest
import StringIO

from mock import patch

from shut import UnixTimeParser


class TestShut(unittest.TestCase):

    def setUp(self):
        self.utp = UnixTimeParser('2015-01-01', '2015-10-01', 'UTC')
        self.utp_pacific = UnixTimeParser('2015-01-01', '2015-10-01', 'US/Pacific')

    def test_shape_unix_time_unchanged_input(self):
        with patch('sys.stdout', new=StringIO.StringIO()) as fakeOutput:
            sys.stdin = StringIO.StringIO('asdlkj')
            self.utp.shape_unix_time()
            assert fakeOutput.getvalue().strip() == 'asdlkj'

    def test_shape_unix_time_converted(self):
        with patch('sys.stdout', new=StringIO.StringIO()) as fakeOutput:
            sys.stdin = StringIO.StringIO('asdlkj,1443304641,more_text,1443304642')
            self.utp_pacific.shape_unix_time()
            assert fakeOutput.getvalue().strip() == 'asdlkj,2015-09-26 14:57:21,more_text,2015-09-26 14:57:22'

    def test_shape_unix_time_converted_utc(self):
        with patch('sys.stdout', new=StringIO.StringIO()) as fakeOutput:
            sys.stdin = StringIO.StringIO('asdlkj,1443304641,more_text,1443304642')
            self.utp.shape_unix_time()
            assert fakeOutput.getvalue().strip() == 'asdlkj,2015-09-26 21:57:21,more_text,2015-09-26 21:57:22'

    def test_command_line_execution(self):
        # TODO test command line execution
        # Popen('cat ./README.md | ./shut/shut.py')
        pass

if __name__ == '__main__':
    TestShut()

@@ -120,16 +120,34 @@
 e.%0A%22%22%22%0A%0A
+import subprocess%0A
 import s
@@ -1504,33 +1504,448 @@
     
-# TODO test command 
+proc = subprocess.check_output(%0A            'echo %5C'%7B%22ts%22: 1440999387, %22msg%22: %22%22%7D%5C' %7C ./shut/shut.py',%0A            shell=True)%0A        assert '2015-08-31 05:36:27' in proc%0A%0A    def test_command_line_execution_min(self):%0A        proc = subprocess.check_output(%0A            'echo %5C'%7B%22ts%22: 584928000, %22msg%22: %22%22%7D%5C' %7C ./shut/shut.py -m 1988-01-01',%0A            shell=True)%0A        assert '1988-07-15 00:00:00' in proc%0A%0A    def test_command_
 line
- 
+_
 exec
@@ -1953,73 +1953,565 @@
 tion
-%0A        # Popen('cat ./README.md %7C ./shut/shut.py')%0A        pass
+_min_max(self):%0A        proc = subprocess.check_output(%0A            'echo %5C'%7B%22ts%22: 584928000, %22msg%22: %22$1435086362.00%22%7D%5C' %7C ./shut/shut.py -m 1988-01-01 -M 2013-02-14',%0A            shell=True)%0A        assert '1988-07-15 00:00:00' in proc and '$1435086362.00' in proc%0A%0A    def test_command_line_execution_min_tz(self):%0A        proc = subprocess.check_output(%0A            'echo %5C'%7B%22ts%22: 584928000, %22msg%22: %22$1435086362.00%22%7D%5C' %7C ./shut/shut.py -m 1988-01-01 -t US%5C/Pacific',%0A            shell=True)%0A        print proc%0A        assert '1988-07-14 17:00:00' in proc
 %0A%0Aif

Complete test cases