Beispiel #1
0
 def setUp(self):
     super(TestCharts, self).setUp()
     self.ch = Chart(self.task)
Beispiel #2
0
class TestCharts(FocusSetup):
    def setUp(self):
        super(TestCharts, self).setUp()
        self.ch = Chart(self.task)

    def tearDown(self):
        super(TestCharts, self).tearDown()

    def test_repr(self):
        ok_(self.ch.__repr__())

    def test_bool_js(self):
        eq_(bool_js(True), "true")
        eq_(bool_js(False), "false")

    def test_resample_w(self):
        d1 = datetime(2016, 1, 1, 1, 1, 1)
        d2 = datetime(2016, 12, 1, 1, 1, 1)
        e1 = Entry(date=d1, value=1.0)
        e2 = Entry(date=d2, value=2.0)
        resampled = resample([e1, e2], by="Y")
        eq_(resampled[0], [2016])

    @raises(NotImplementedError)
    def test_resampled_err(self):
        resample(self.ch.entries, by="XYZ")

    def test_resample_chart(self):
        self.ch.resample(by="W")
        ok_(self.ch._x())

    def test_ffill_days(self):
        today = timezone.now().date()
        last_week = today - timedelta(days=6)
        groups = {last_week: 5, today: 10}
        filled = ffill(groups, by="d")
        eq_(len(filled), 7)

    def test_ffill_months(self):
        today = reduce_by_month(timezone.now())
        last_year = today.replace(year=today.year - 1)
        groups = {last_year: 5, today: 10}
        filled = ffill(groups, by="M")
        eq_(len(filled), 13)

    def test_ffill_weeks(self):
        today = reduce_by_week(timezone.now())
        another_week = today + timedelta(days=14)
        groups = {reduce_by_week(another_week): 5, today: 10}
        filled = ffill(groups, by="W")
        eq_(len(filled), 3)

    @raises(NotImplementedError)
    def test_ffill_notimplemented(self):
        today = reduce_by_week(timezone.now())
        another_week = today + timedelta(days=14)
        groups = {reduce_by_week(another_week): 5, today: 10}
        ffill(groups, by="XYZ")

    def test_reduce_by_day(self):
        eq_(reduce_by_day(timezone.now()), timezone.now().date())
        eq_(reduce_by_day(timezone.now().date()), timezone.now().date())