import unittest
try:
    from unittest import mock
except ImportError:
    import mock
from pi3bar.plugins.uptime import get_uptime_seconds, uptime_format, Uptime


class GetUptimeSecondsTestCase(unittest.TestCase):
    def test(self):
        m = mock.mock_open(read_data='5')
        m.return_value.readline.return_value = '5'  # py33
        with mock.patch('pi3bar.plugins.uptime.open', m, create=True):
            seconds = get_uptime_seconds()
        self.assertEqual(5, seconds)


class UptimeFormatTestCase(unittest.TestCase):
    def test_seconds(self):
        s = uptime_format(5)
        self.assertEqual('0:00:00:05', s)

    def test_minutes(self):
        s = uptime_format(3540)
        self.assertEqual('0:00:59:00', s)

    def test_hours(self):
        s = uptime_format(49020)
        self.assertEqual('0:13:37:00', s)

    def test_days(self):
        


    def test_format_days_applied_to_hours(self):
        s = uptime_format(135420, '%H:%M:%S')
        self.assertEqual('37:37:00', s)

    def test_format_hours_applied_to_minutes(self):
        s = uptime_format(49020, '%M:%S')
        self.assertEqual('817:00', s)


class UptimeTestCase(unittest.TestCase):
    def test(self):
        plugin = Uptime()
        self.assertEqual('%d days %H:%M:%S up', plugin.full_format)
        self.assertEqual('%dd %H:%M up', plugin.short_format)

    @mock.patch('pi3bar.plugins.uptime.get_uptime_seconds')
    def test_cycle(self, mock_get_uptime_seconds):
        plugin = Uptime()

        mock_get_uptime_seconds.return_value = 49020
        plugin.cycle()

        self.assertEqual('0 days 13:37:00 up', plugin.full_text)
        self.assertEqual('0d 13:37 up', plugin.short_text)

s = uptime_format(135420)
        self.assertEqual('1:13:37:00', s)