# Path: ratechecker/dataset.py
# class CoverSheet(object):
#     def __init__(self, f):
#         self.tree = ET.parse(f)
# 
#         if not self.date:
#             raise ValueError("missing date")
# 
#         if not self.expected_scenario_results:
#             raise ValueError("missing scenario results")
# 
#     @property
#     def date(self):
#         node = self.tree.find("ProcessDate/Date")
# 
#         if node is not None:
#             return datetime.strptime(node.text, "%Y%m%d").date()
# 
#     @property
#     def expected_scenario_results(self):
#         results = OrderedDict()
# 
#         for scenario in self.tree.getiterator(tag="Scenario"):
#             scenario_data = {elem.tag: elem.text for elem in scenario}
#             scenario_id = int(scenario_data["ScenarioNo"])
# 
#             results[scenario_id] = (
#                 scenario_data["AdjustedRates"] or None,
#                 scenario_data["AdjustedPoints"] or None,
#             )
# 
#         return results
# 
# Path: ratechecker/tests/helpers.py
# def get_sample_dataset(day=None, datasets={}):
#     return Dataset(get_sample_dataset_zipfile(day=day, datasets=datasets))


from datetime import date, datetime
from unittest import TestCase
from xml.etree.cElementTree import ParseError
from django.core.files.base import ContentFile
from django.utils import timezone
from mock import Mock
from ratechecker.dataset import CoverSheet
from ratechecker.tests.helpers import get_sample_dataset



class TestDataset(TestCase):
    def test_cover_sheet(self):
        dataset = get_sample_dataset()
        self.assertIsInstance(dataset.cover_sheet, CoverSheet)

    def test_timestamp(self):
        dataset = get_sample_dataset(day=date(2017, 4, 3))
        self.assertEqual(
            dataset.timestamp,
            timezone.make_aware(
                datetime(2017, 4, 3, 0, 0, 0), timezone.get_current_timezone()
            ),
        )

    def test_load_calls_loaders(self):
        dataset = get_sample_dataset(
            day=date(2017, 4, 3), datasets={"20170403_key.txt": "testing"}
        )

        loader = Mock()
        loader.return_value = loader
        dataset.loaders = {"key": loader}
        dataset.load()

        loader.load.assert_called_once()

    def test_load_fails_if_dataset_missing(self):

# Path: ratechecker/dataset.py
# class CoverSheet(object):
#     def __init__(self, f):
#         self.tree = ET.parse(f)
# 
#         if not self.date:
#             raise ValueError("missing date")
# 
#         if not self.expected_scenario_results:
#             raise ValueError("missing scenario results")
# 
#     @property
#     def date(self):
#         node = self.tree.find("ProcessDate/Date")
# 
#         if node is not None:
#             return datetime.strptime(node.text, "%Y%m%d").date()
# 
#     @property
#     def expected_scenario_results(self):
#         results = OrderedDict()
# 
#         for scenario in self.tree.getiterator(tag="Scenario"):
#             scenario_data = {elem.tag: elem.text for elem in scenario}
#             scenario_id = int(scenario_data["ScenarioNo"])
# 
#             results[scenario_id] = (
#                 scenario_data["AdjustedRates"] or None,
#                 scenario_data["AdjustedPoints"] or None,
#             )
# 
#         return results
# 
# Path: ratechecker/tests/helpers.py
# def get_sample_dataset(day=None, datasets={}):
#     return Dataset(get_sample_dataset_zipfile(day=day, datasets=datasets))


# Path: ratechecker/tests/test_dataset.py
from datetime import date, datetime
from unittest import TestCase
from xml.etree.cElementTree import ParseError
from django.core.files.base import ContentFile
from django.utils import timezone
from mock import Mock
from ratechecker.dataset import CoverSheet
from ratechecker.tests.helpers import get_sample_dataset




class TestDataset(TestCase):
    def test_cover_sheet(self):
        dataset = get_sample_dataset()
        self.assertIsInstance(dataset.cover_sheet, CoverSheet)

    def test_timestamp(self):
        dataset = get_sample_dataset(day=date(2017, 4, 3))
        self.assertEqual(
            dataset.timestamp,
            timezone.make_aware(
                datetime(2017, 4, 3, 0, 0, 0), timezone.get_current_timezone()
            ),
        )

    def test_load_calls_loaders(self):
        dataset = get_sample_dataset(
            day=date(2017, 4, 3), datasets={"20170403_key.txt": "testing"}
        )

        loader = Mock()
        loader.return_value = loader
        dataset.loaders = {"key": loader}
        dataset.load()

        loader.load.assert_called_once()

    def test_load_fails_if_dataset_missing(self):

        dataset = get_sample_dataset(