# -*- coding: utf-8 -*-

#  marketanalysis
#  ----------------
#  A fast, efficient Python library for generating country, province and state
#  specific sets of marketmarketholidayss on the fly. It aims to make determining whether a
#  specific date is a holiday as fast and flexible as possible.
#
#  Author:  MichealOmojola <momojola@aust.edu.ng>
#  Website: https://github.com/OmoMicheal/trading_days
#  License: MIT (see LICENSE file)
#  Version: 0.1 (April 7, 2021)

import unittest

from datetime import date
from dateutil.relativedelta import relativedelta

# import sys
# sys.path.insert(0, 'C:/Users/momojola/projects/marketanalysis/marketanalysis/')

from marketanalysis import marketholidays
from marketanalysis import markettradingdays


class TestUS(unittest.TestCase):
    def setUp(self):
        self.marketholidayss = marketholidays.USA(observed=False)
        self.markettradingdayss = markettradingdays.USA()

    def test_new_years(self):
        self.assertNotIn(date(2010, 12, 31), self.marketholidayss)
        self.assertNotIn(date(2017, 1, 2), self.marketholidayss)
        self.marketholidayss.observed = True
        self.assertIn(date(2010, 12, 31), self.marketholidayss)
        self.assertIn(date(2017, 1, 2), self.marketholidayss)
        self.marketholidayss.observed = False
        for year in range(1900, 2100):
            dt = date(year, 1, 1)
            self.assertIn(dt, self.marketholidayss)
            self.assertNotIn(dt + relativedelta(days=-1), self.marketholidayss)
            self.assertNotIn(dt + relativedelta(days=+1), self.marketholidayss)


    def test_martin_luther(self):
        for dt in [
            date(1986, 1, 20),
            date(1999, 1, 18),
            date(2000, 1, 17),
            date(2012, 1, 16),
            date(2013, 1, 21),
            date(2014, 1, 20),
            date(2015, 1, 19),
            date(2016, 1, 18),
            date(2020, 1, 20),
        ]:
            self.assertIn(dt, self.marketholidayss)
            self.assertNotIn(dt + relativedelta(days=-1), self.marketholidayss)
            self.assertNotIn(dt + relativedelta(days=+1), self.marketholidayss)
    

    def test_washingtons_birthday(self):
        de_marketholidayss = marketholidays.US()
        for dt in [
            date(1969, 2, 22),
            date(1970, 2, 22),
            date(1971, 2, 15),
            date(1997, 2, 17),
            date(1999, 2, 15),
            date(2000, 2, 21),
            date(2012, 2, 20),
            date(2013, 2, 18),
            date(2014, 2, 17),
            date(2015, 2, 16),
            date(2016, 2, 15),
            date(2020, 2, 17),
        ]:
            self.assertIn(dt, self.marketholidayss)
            self.assertNotIn(dt + relativedelta(days=-1), self.marketholidayss)
            self.assertNotIn(dt + relativedelta(days=+1), self.marketholidayss)
            self.assertIn(dt, de_marketholidayss)    
        self.assertEqual(marketholidays.US().get("2015-02-16"), "Presidents' Day")
       

    def test_good_friday(self):
        marketholidayss_US = marketholidays.US()
        for dt in [
            date(1900, 4, 13),
            date(1901, 4, 5),
            date(1902, 3, 28),
            date(1999, 4, 2),
            date(2000, 4, 21),
            date(2010, 4, 2),
            date(2018, 3, 30),
            date(2019, 4, 19),
            date(2020, 4, 10),
        ]:
            self.assertIn(dt, self.marketholidayss)
            self.assertIn(dt, marketholidayss_US)


    def test_memorial_day(self):
        for dt in [
            date(1969, 5, 30),
            date(1970, 5, 30),
            date(1971, 5, 31),
            date(1997, 5, 26),
            date(1999, 5, 31),
            date(2000, 5, 29),
            date(2012, 5, 28),
            date(2013, 5, 27),
            date(2014, 5, 26),
            date(2015, 5, 25),
            date(2016, 5, 30),
            date(2020, 5, 25),
        ]:
            self.assertIn(dt, self.marketholidayss)
            self.assertNotIn(dt + relativedelta(days=-1), self.marketholidayss)
            self.assertNotIn(dt + relativedelta(days=+1), self.marketholidayss)

  

    def test_independence_day(self):
        for year in range(1900, 2100):
            dt = date(year, 7, 4)
            self.assertIn(dt, self.marketholidayss)
            self.assertNotIn(dt + relativedelta(days=-1), self.marketholidayss)
            self.assertNotIn(dt + relativedelta(days=+1), self.marketholidayss)
        self.assertNotIn(date(2010, 7, 5), self.marketholidayss)
        self.assertNotIn(date(2020, 7, 3), self.marketholidayss)
        self.marketholidayss.observed = True
        self.assertIn(date(2010, 7, 5), self.marketholidayss)
        self.assertIn(date(2020, 7, 3), self.marketholidayss)

    def test_labor_day(self):
        for dt in [
            date(1997, 9, 1),
            date(1999, 9, 6),
            date(2000, 9, 4),
            date(2012, 9, 3),
            date(2013, 9, 2),
            date(2014, 9, 1),
            date(2015, 9, 7),
            date(2016, 9, 5),
            date(2020, 9, 7),
        ]:
            self.assertIn(dt, self.marketholidayss)
            self.assertNotIn(dt + relativedelta(days=-1), self.marketholidayss)
            self.assertNotIn(dt + relativedelta(days=+1), self.marketholidayss)

    def test_thanksgiving_day(self):
        for dt in [
            date(1997, 11, 27),
            date(1999, 11, 25),
            date(2000, 11, 23),
            date(2012, 11, 22),
            date(2013, 11, 28),
            date(2014, 11, 27),
            date(2015, 11, 26),
            date(2016, 11, 24),
            date(2020, 11, 26),
        ]:
            self.assertNotIn(dt, self.marketholidayss)
            self.assertNotIn(dt + relativedelta(days=-1), self.marketholidayss)
            self.assertNotIn(dt + relativedelta(days=+1), self.marketholidayss)


    def test_christmas_eve(self):
        as_marketholidayss = marketholidays.US()
        self.marketholidayss.observed = False
        for year in range(1900, 2050):
            self.assertNotIn(date(year, 12, 24), self.marketholidayss)
            # self.assertIn(date(year, 12, 24), as_marketholidayss)
        self.assertNotIn(date(2016, 12, 23), as_marketholidayss)
        self.assertNotIn(
            "Christmas Eve (Observed)",
            as_marketholidayss.get_list(date(2017, 12, 22)),
        )
        
    def test_christmas_day(self):
        for year in range(1900, 2100):
            dt = date(year, 12, 25)
            self.assertIn(dt, self.marketholidayss)
            self.assertNotIn(dt + relativedelta(days=-1), self.marketholidayss)
            self.assertNotIn(dt + relativedelta(days=+1), self.marketholidayss)
        self.assertNotIn(date(2010, 12, 24), self.marketholidayss)
        self.assertNotIn(date(2016, 12, 26), self.marketholidayss)
        self.marketholidayss.observed = True
        self.assertIn(date(2010, 12, 24), self.marketholidayss)
        self.assertIn(date(2016, 12, 26), self.marketholidayss)

    def test_day_after_christmas(self):
        nc_marketholidayss = marketholidays.US(observed=False)
        self.assertNotIn(date(2015, 12, 28), nc_marketholidayss)
        self.assertNotIn(date(2016, 12, 27), nc_marketholidayss)
        nc_marketholidayss.observed = True
        
        

    def test_new_years_eve(self):
        ky_marketholidayss = marketholidays.US()
        self.assertNotIn(date(2012, 12, 31), ky_marketholidayss)
        for dt in [date(2013, 12, 31), date(2016, 12, 30)]:
            self.assertNotIn(dt, self.marketholidayss)
            self.assertNotIn(dt, ky_marketholidayss)
            
    def test_future_list(self):
        current_date = '2021-04-13'
        lookup_step = 10
        self.assertIn(date(2021, 4, 16), self.markettradingdayss.future_list(current_date, lookup_step))
        self.assertNotIn(date(2021, 4, 18), self.markettradingdayss.future_list(current_date, lookup_step))
        
    def test_prevDays(self):
        current_date = '2021-04-13'
        lookback_step = 4
        self.assertIn(date(2021, 4, 9), self.markettradingdayss.prevDays(current_date, lookback_step))
        self.assertNotIn(date(2021, 4, 11), self.markettradingdayss.prevDays(current_date, lookback_step))

    def test_BtwDates(self):
        current_date = '2021-04-13'
        future_date = '2021-04-20'
        self.assertIn(date(2021, 4, 15), self.markettradingdayss.BtwDates(current_date, future_date))
        self.assertNotIn(date(2021, 4, 18), self.markettradingdayss.BtwDates(current_date, future_date))
        

# if __name__ == "__main__":
#     unittest.main()
[(28, 'marketanalysis.marketholidays.USA', 'marketholidays.USA', ([], {'observed': '(False)'}), False, 'from marketanalysis import marketholidays\n'), (29, 'marketanalysis.markettradingdays.USA', 'markettradingdays.USA', ([], {}), False, 'from marketanalysis import markettradingdays\n'), (63, 'marketanalysis.marketholidays.US', 'marketholidays.US', ([], {}), False, 'from marketanalysis import marketholidays\n'), (86, 'marketanalysis.marketholidays.US', 'marketholidays.US', ([], {}), False, 'from marketanalysis import marketholidays\n'), (169, 'marketanalysis.marketholidays.US', 'marketholidays.US', ([], {}), False, 'from marketanalysis import marketholidays\n'), (193, 'marketanalysis.marketholidays.US', 'marketholidays.US', ([], {'observed': '(False)'}), False, 'from marketanalysis import marketholidays\n'), (201, 'marketanalysis.marketholidays.US', 'marketholidays.US', ([], {}), False, 'from marketanalysis import marketholidays\n'), (32, 'datetime.date', 'date', (['(2010)', '(12)', '(31)'], {}), False, 'from datetime import date\n'), (33, 'datetime.date', 'date', (['(2017)', '(1)', '(2)'], {}), False, 'from datetime import date\n'), (35, 'datetime.date', 'date', (['(2010)', '(12)', '(31)'], {}), False, 'from datetime import date\n'), (36, 'datetime.date', 'date', (['(2017)', '(1)', '(2)'], {}), False, 'from datetime import date\n'), (39, 'datetime.date', 'date', (['year', '(1)', '(1)'], {}), False, 'from datetime import date\n'), (47, 'datetime.date', 'date', (['(1986)', '(1)', '(20)'], {}), False, 'from datetime import date\n'), (48, 'datetime.date', 'date', (['(1999)', '(1)', '(18)'], {}), False, 'from datetime import date\n'), (49, 'datetime.date', 'date', (['(2000)', '(1)', '(17)'], {}), False, 'from datetime import date\n'), (50, 'datetime.date', 'date', (['(2012)', '(1)', '(16)'], {}), False, 'from datetime import date\n'), (51, 'datetime.date', 'date', (['(2013)', '(1)', '(21)'], {}), False, 'from datetime import date\n'), (52, 'datetime.date', 'date', (['(2014)', '(1)', '(20)'], {}), False, 'from datetime import date\n'), (53, 'datetime.date', 'date', (['(2015)', '(1)', '(19)'], {}), False, 'from datetime import date\n'), (54, 'datetime.date', 'date', (['(2016)', '(1)', '(18)'], {}), False, 'from datetime import date\n'), (55, 'datetime.date', 'date', (['(2020)', '(1)', '(20)'], {}), False, 'from datetime import date\n'), (65, 'datetime.date', 'date', (['(1969)', '(2)', '(22)'], {}), False, 'from datetime import date\n'), (66, 'datetime.date', 'date', (['(1970)', '(2)', '(22)'], {}), False, 'from datetime import date\n'), (67, 'datetime.date', 'date', (['(1971)', '(2)', '(15)'], {}), False, 'from datetime import date\n'), (68, 'datetime.date', 'date', (['(1997)', '(2)', '(17)'], {}), False, 'from datetime import date\n'), (69, 'datetime.date', 'date', (['(1999)', '(2)', '(15)'], {}), False, 'from datetime import date\n'), (70, 'datetime.date', 'date', (['(2000)', '(2)', '(21)'], {}), False, 'from datetime import date\n'), (71, 'datetime.date', 'date', (['(2012)', '(2)', '(20)'], {}), False, 'from datetime import date\n'), (72, 'datetime.date', 'date', (['(2013)', '(2)', '(18)'], {}), False, 'from datetime import date\n'), (73, 'datetime.date', 'date', (['(2014)', '(2)', '(17)'], {}), False, 'from datetime import date\n'), (74, 'datetime.date', 'date', (['(2015)', '(2)', '(16)'], {}), False, 'from datetime import date\n'), (75, 'datetime.date', 'date', (['(2016)', '(2)', '(15)'], {}), False, 'from datetime import date\n'), (76, 'datetime.date', 'date', (['(2020)', '(2)', '(17)'], {}), False, 'from datetime import date\n'), (88, 'datetime.date', 'date', (['(1900)', '(4)', '(13)'], {}), False, 'from datetime import date\n'), (89, 'datetime.date', 'date', (['(1901)', '(4)', '(5)'], {}), False, 'from datetime import date\n'), (90, 'datetime.date', 'date', (['(1902)', '(3)', '(28)'], {}), False, 'from datetime import date\n'), (91, 'datetime.date', 'date', (['(1999)', '(4)', '(2)'], {}), False, 'from datetime import date\n'), (92, 'datetime.date', 'date', (['(2000)', '(4)', '(21)'], {}), False, 'from datetime import date\n'), (93, 'datetime.date', 'date', (['(2010)', '(4)', '(2)'], {}), False, 'from datetime import date\n'), (94, 'datetime.date', 'date', (['(2018)', '(3)', '(30)'], {}), False, 'from datetime import date\n'), (95, 'datetime.date', 'date', (['(2019)', '(4)', '(19)'], {}), False, 'from datetime import date\n'), (96, 'datetime.date', 'date', (['(2020)', '(4)', '(10)'], {}), False, 'from datetime import date\n'), (104, 'datetime.date', 'date', (['(1969)', '(5)', '(30)'], {}), False, 'from datetime import date\n'), (105, 'datetime.date', 'date', (['(1970)', '(5)', '(30)'], {}), False, 'from datetime import date\n'), (106, 'datetime.date', 'date', (['(1971)', '(5)', '(31)'], {}), False, 'from datetime import date\n'), (107, 'datetime.date', 'date', (['(1997)', '(5)', '(26)'], {}), False, 'from datetime import date\n'), (108, 'datetime.date', 'date', (['(1999)', '(5)', '(31)'], {}), False, 'from datetime import date\n'), (109, 'datetime.date', 'date', (['(2000)', '(5)', '(29)'], {}), False, 'from datetime import date\n'), (110, 'datetime.date', 'date', (['(2012)', '(5)', '(28)'], {}), False, 'from datetime import date\n'), (111, 'datetime.date', 'date', (['(2013)', '(5)', '(27)'], {}), False, 'from datetime import date\n'), (112, 'datetime.date', 'date', (['(2014)', '(5)', '(26)'], {}), False, 'from datetime import date\n'), (113, 'datetime.date', 'date', (['(2015)', '(5)', '(25)'], {}), False, 'from datetime import date\n'), (114, 'datetime.date', 'date', (['(2016)', '(5)', '(30)'], {}), False, 'from datetime import date\n'), (115, 'datetime.date', 'date', (['(2020)', '(5)', '(25)'], {}), False, 'from datetime import date\n'), (125, 'datetime.date', 'date', (['year', '(7)', '(4)'], {}), False, 'from datetime import date\n'), (129, 'datetime.date', 'date', (['(2010)', '(7)', '(5)'], {}), False, 'from datetime import date\n'), (130, 'datetime.date', 'date', (['(2020)', '(7)', '(3)'], {}), False, 'from datetime import date\n'), (132, 'datetime.date', 'date', (['(2010)', '(7)', '(5)'], {}), False, 'from datetime import date\n'), (133, 'datetime.date', 'date', (['(2020)', '(7)', '(3)'], {}), False, 'from datetime import date\n'), (137, 'datetime.date', 'date', (['(1997)', '(9)', '(1)'], {}), False, 'from datetime import date\n'), (138, 'datetime.date', 'date', (['(1999)', '(9)', '(6)'], {}), False, 'from datetime import date\n'), (139, 'datetime.date', 'date', (['(2000)', '(9)', '(4)'], {}), False, 'from datetime import date\n'), (140, 'datetime.date', 'date', (['(2012)', '(9)', '(3)'], {}), False, 'from datetime import date\n'), (141, 'datetime.date', 'date', (['(2013)', '(9)', '(2)'], {}), False, 'from datetime import date\n'), (142, 'datetime.date', 'date', (['(2014)', '(9)', '(1)'], {}), False, 'from datetime import date\n'), (143, 'datetime.date', 'date', (['(2015)', '(9)', '(7)'], {}), False, 'from datetime import date\n'), (144, 'datetime.date', 'date', (['(2016)', '(9)', '(5)'], {}), False, 'from datetime import date\n'), (145, 'datetime.date', 'date', (['(2020)', '(9)', '(7)'], {}), False, 'from datetime import date\n'), (153, 'datetime.date', 'date', (['(1997)', '(11)', '(27)'], {}), False, 'from datetime import date\n'), (154, 'datetime.date', 'date', (['(1999)', '(11)', '(25)'], {}), False, 'from datetime import date\n'), (155, 'datetime.date', 'date', (['(2000)', '(11)', '(23)'], {}), False, 'from datetime import date\n'), (156, 'datetime.date', 'date', (['(2012)', '(11)', '(22)'], {}), False, 'from datetime import date\n'), (157, 'datetime.date', 'date', (['(2013)', '(11)', '(28)'], {}), False, 'from datetime import date\n'), (158, 'datetime.date', 'date', (['(2014)', '(11)', '(27)'], {}), False, 'from datetime import date\n'), (159, 'datetime.date', 'date', (['(2015)', '(11)', '(26)'], {}), False, 'from datetime import date\n'), (160, 'datetime.date', 'date', (['(2016)', '(11)', '(24)'], {}), False, 'from datetime import date\n'), (161, 'datetime.date', 'date', (['(2020)', '(11)', '(26)'], {}), False, 'from datetime import date\n'), (174, 'datetime.date', 'date', (['(2016)', '(12)', '(23)'], {}), False, 'from datetime import date\n'), (182, 'datetime.date', 'date', (['year', '(12)', '(25)'], {}), False, 'from datetime import date\n'), (186, 'datetime.date', 'date', (['(2010)', '(12)', '(24)'], {}), False, 'from datetime import date\n'), (187, 'datetime.date', 'date', (['(2016)', '(12)', '(26)'], {}), False, 'from datetime import date\n'), (189, 'datetime.date', 'date', (['(2010)', '(12)', '(24)'], {}), False, 'from datetime import date\n'), (190, 'datetime.date', 'date', (['(2016)', '(12)', '(26)'], {}), False, 'from datetime import date\n'), (194, 'datetime.date', 'date', (['(2015)', '(12)', '(28)'], {}), False, 'from datetime import date\n'), (195, 'datetime.date', 'date', (['(2016)', '(12)', '(27)'], {}), False, 'from datetime import date\n'), (202, 'datetime.date', 'date', (['(2012)', '(12)', '(31)'], {}), False, 'from datetime import date\n'), (203, 'datetime.date', 'date', (['(2013)', '(12)', '(31)'], {}), False, 'from datetime import date\n'), (203, 'datetime.date', 'date', (['(2016)', '(12)', '(30)'], {}), False, 'from datetime import date\n'), (210, 'datetime.date', 'date', (['(2021)', '(4)', '(16)'], {}), False, 'from datetime import date\n'), (211, 'datetime.date', 'date', (['(2021)', '(4)', '(18)'], {}), False, 'from datetime import date\n'), (216, 'datetime.date', 'date', (['(2021)', '(4)', '(9)'], {}), False, 'from datetime import date\n'), (217, 'datetime.date', 'date', (['(2021)', '(4)', '(11)'], {}), False, 'from datetime import date\n'), (222, 'datetime.date', 'date', (['(2021)', '(4)', '(15)'], {}), False, 'from datetime import date\n'), (223, 'datetime.date', 'date', (['(2021)', '(4)', '(18)'], {}), False, 'from datetime import date\n'), (172, 'datetime.date', 'date', (['year', '(12)', '(24)'], {}), False, 'from datetime import date\n'), (177, 'datetime.date', 'date', (['(2017)', '(12)', '(22)'], {}), False, 'from datetime import date\n'), (41, 'dateutil.relativedelta.relativedelta', 'relativedelta', ([], {'days': '(-1)'}), False, 'from dateutil.relativedelta import relativedelta\n'), (42, 'dateutil.relativedelta.relativedelta', 'relativedelta', ([], {'days': '(+1)'}), False, 'from dateutil.relativedelta import relativedelta\n'), (58, 'dateutil.relativedelta.relativedelta', 'relativedelta', ([], {'days': '(-1)'}), False, 'from dateutil.relativedelta import relativedelta\n'), (59, 'dateutil.relativedelta.relativedelta', 'relativedelta', ([], {'days': '(+1)'}), False, 'from dateutil.relativedelta import relativedelta\n'), (79, 'dateutil.relativedelta.relativedelta', 'relativedelta', ([], {'days': '(-1)'}), False, 'from dateutil.relativedelta import relativedelta\n'), (80, 'dateutil.relativedelta.relativedelta', 'relativedelta', ([], {'days': '(+1)'}), False, 'from dateutil.relativedelta import relativedelta\n'), (82, 'marketanalysis.marketholidays.US', 'marketholidays.US', ([], {}), False, 'from marketanalysis import marketholidays\n'), (118, 'dateutil.relativedelta.relativedelta', 'relativedelta', ([], {'days': '(-1)'}), False, 'from dateutil.relativedelta import relativedelta\n'), (119, 'dateutil.relativedelta.relativedelta', 'relativedelta', ([], {'days': '(+1)'}), False, 'from dateutil.relativedelta import relativedelta\n'), (127, 'dateutil.relativedelta.relativedelta', 'relativedelta', ([], {'days': '(-1)'}), False, 'from dateutil.relativedelta import relativedelta\n'), (128, 'dateutil.relativedelta.relativedelta', 'relativedelta', ([], {'days': '(+1)'}), False, 'from dateutil.relativedelta import relativedelta\n'), (148, 'dateutil.relativedelta.relativedelta', 'relativedelta', ([], {'days': '(-1)'}), False, 'from dateutil.relativedelta import relativedelta\n'), (149, 'dateutil.relativedelta.relativedelta', 'relativedelta', ([], {'days': '(+1)'}), False, 'from dateutil.relativedelta import relativedelta\n'), (164, 'dateutil.relativedelta.relativedelta', 'relativedelta', ([], {'days': '(-1)'}), False, 'from dateutil.relativedelta import relativedelta\n'), (165, 'dateutil.relativedelta.relativedelta', 'relativedelta', ([], {'days': '(+1)'}), False, 'from dateutil.relativedelta import relativedelta\n'), (184, 'dateutil.relativedelta.relativedelta', 'relativedelta', ([], {'days': '(-1)'}), False, 'from dateutil.relativedelta import relativedelta\n'), (185, 'dateutil.relativedelta.relativedelta', 'relativedelta', ([], {'days': '(+1)'}), False, 'from dateutil.relativedelta import relativedelta\n')]