# Path: shpkpr/marathon_lb/stats.py
# class Stats(object):
# 
#     def __init__(self, *instance_stats):
#         self._raw_stats = instance_stats
# 
#     def __iter__(self):
#         return (r for r in self._stats)
# 
#     def __getitem__(self, i):
#         return self._stats[i]
# 
#     def __len__(self):
#         return len(self._stats)
# 
#     @cached_property
#     def _stats(self):
#         """Parse and aggregate all stats files, caching the result
#         """
#         _stats = []
#         for instance_stats in self._raw_stats:
#             _stats.extend(self._parse_instance_stats(instance_stats))
#         return _stats
# 
#     def _parse_instance_stats(self, instance_stats):
#         """Parse a single HAProxy stats CSV file.
#         """
#         rows = instance_stats.splitlines()
#         headers = rows[0].lstrip('# ').rstrip(',\n').split(',')
#         csv_reader = csv.reader(rows[1:], quotechar="'")
# 
#         Row = namedtuple('Row', headers)
#         return [Row(*row[0:-1]) for row in csv_reader if row[0][0] != '#']


import collections
import pytest
from shpkpr.marathon_lb.stats import Stats
# local imports


@pytest.fixture
def haproxy_stats(file_fixture):
    csv_data = file_fixture("haproxy/stats.csv")
    return Stats(csv_data)


def test_stats_is_iterable(haproxy_stats):
    assert isinstance(haproxy_stats, collections.Iterable)


def test_stats_can_be_indexed(haproxy_stats):
    try:
        haproxy_stats[0]
        haproxy_stats[-1]
    except IndexError as e:
        pytest.fail("Unable to index `Stats` instance: {0}".format(e))


def test_stats_have_a_length(haproxy_stats):
    try:
        len(haproxy_stats)
    except TypeError as e:
        pytest.fail("`Stats` instance does not have a length: {0}".format(e))


def test_stats_does_not_contain_commented_rows(haproxy_stats):
    for stat in haproxy_stats:

# Path: shpkpr/marathon_lb/stats.py
# class Stats(object):
# 
#     def __init__(self, *instance_stats):
#         self._raw_stats = instance_stats
# 
#     def __iter__(self):
#         return (r for r in self._stats)
# 
#     def __getitem__(self, i):
#         return self._stats[i]
# 
#     def __len__(self):
#         return len(self._stats)
# 
#     @cached_property
#     def _stats(self):
#         """Parse and aggregate all stats files, caching the result
#         """
#         _stats = []
#         for instance_stats in self._raw_stats:
#             _stats.extend(self._parse_instance_stats(instance_stats))
#         return _stats
# 
#     def _parse_instance_stats(self, instance_stats):
#         """Parse a single HAProxy stats CSV file.
#         """
#         rows = instance_stats.splitlines()
#         headers = rows[0].lstrip('# ').rstrip(',\n').split(',')
#         csv_reader = csv.reader(rows[1:], quotechar="'")
# 
#         Row = namedtuple('Row', headers)
#         return [Row(*row[0:-1]) for row in csv_reader if row[0][0] != '#']


# Path: tests/marathon_lb/test_stats.py
import collections
import pytest
from shpkpr.marathon_lb.stats import Stats

# local imports


@pytest.fixture
def haproxy_stats(file_fixture):
    csv_data = file_fixture("haproxy/stats.csv")
    return Stats(csv_data)


def test_stats_is_iterable(haproxy_stats):
    assert isinstance(haproxy_stats, collections.Iterable)


def test_stats_can_be_indexed(haproxy_stats):
    try:
        haproxy_stats[0]
        haproxy_stats[-1]
    except IndexError as e:
        pytest.fail("Unable to index `Stats` instance: {0}".format(e))


def test_stats_have_a_length(haproxy_stats):
    try:
        len(haproxy_stats)
    except TypeError as e:
        pytest.fail("`Stats` instance does not have a length: {0}".format(e))


def test_stats_does_not_contain_commented_rows(haproxy_stats):
    for stat in haproxy_stats:

        assert not stat[0].startswith("#")