# 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
    def test_datafile(self):
        dataset = get_sample_dataset(
            day=date(2017, 4, 3),
            datasets={"20170403_something.txt": "testing"},
        )

        f = dataset.datafile("something")
        self.assertEqual(f.read(), b"testing")


class TestCoverSheet(TestCase):
    def test_null_file_raises_typeerror(self):
        with self.assertRaises(TypeError):
            CoverSheet(None)

    def test_invalid_xml_file_raises_parseerror(self):
        f = ContentFile("foo")
        with self.assertRaises(ParseError):
            CoverSheet(f)

    def test_missing_date_raises_valueerror(self):
        f = ContentFile("<data></data>")
        with self.assertRaises(ValueError):
            CoverSheet(f)

    def test_invalid_date_raises_valueerror(self):
        f = ContentFile(
            "<data>" "<ProcessDate><Date>foo</Date></ProcessDate>" "</data>"
        )
        with self.assertRaises(ValueError):

# 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

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

        f = dataset.datafile("something")
        self.assertEqual(f.read(), b"testing")


class TestCoverSheet(TestCase):
    def test_null_file_raises_typeerror(self):
        with self.assertRaises(TypeError):
            CoverSheet(None)

    def test_invalid_xml_file_raises_parseerror(self):
        f = ContentFile("foo")
        with self.assertRaises(ParseError):
            CoverSheet(f)

    def test_missing_date_raises_valueerror(self):
        f = ContentFile("<data></data>")
        with self.assertRaises(ValueError):
            CoverSheet(f)

    def test_invalid_date_raises_valueerror(self):
        f = ContentFile(
            "<data>" "<ProcessDate><Date>foo</Date></ProcessDate>" "</data>"
        )
        with self.assertRaises(ValueError):

            CoverSheet(f)