#!/usr/bin/env python3

import datetime
import unittest


def assume_nothing(val):
    return (
        None
        if type(val) is not datetime.datetime
        else val.strftime("%Y-%m-%d %H:%M:%S")
    )


def assume_eager(val):
    return None if not val else val.strftime("%Y-%m-%d %H:%M:%S")


def assume_lazy(val):
    return val.strftime("%Y-%m-%d %H:%M:%S") if val else None


class PythonLazyDatetime(unittest.TestCase):
    def setUp(self):
        pass

    def tearDown(self):
        pass

    def test_assume_lazy_empty(self):
        val = ""
        result = assume_lazy(val)
        self.assertTrue(not result, result)

    def test_assume_lazy_one_str(self):
        val = "1"
        with self.assertRaises(AttributeError) as context:
            assume_lazy(val)
        self.assertTrue(
            "'str' object has no attribute 'strftime'" == str(context.exception),
            context.exception,
        )

    def test_assume_lazy_datetime_now(self):
        val = datetime.datetime.now()
        result = assume_lazy(val)
        self.assertTrue(result, result)

    def test_assume_nothing_empty(self):
        val = ""
        result = assume_nothing(val)
        self.assertTrue(not result, result)

    def test_assume_nothing_one_str(self):
        val = "1"
        result = assume_nothing(val)
        self.assertTrue(not result, result)

    def test_assume_nothing_datetime_now(self):
        val = datetime.datetime.now()
        result = assume_nothing(val)
        self.assertTrue(result, result)


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