Weather test is broken.... Still.

Bug #374695 reported by Matt Layman
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Entertainer Media Center
Triaged
Medium
Unassigned

Bug Description

Sorry Paul. I was running a `make check` for a code review and the weather test broke again. :( The output below shows nosetests, but the same failure occurred with trial. I just didn't want to paste in all the trial output for proof.

matt@eden:~/repo/sam/entertainerlib/tests$ date
Sun May 10 22:29:35 EDT 2009
matt@eden:~/repo/sam/entertainerlib/tests$ nosetests test_weather.py
..F...
======================================================================
FAIL: entertainerlib.tests.test_weather.WeatherTest.testWeatherFindRemote
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/lib/python2.6/dist-packages/testtools/testcase.py", line 171, in run
    testMethod()
  File "/home/matt/repo/sam/entertainerlib/tests/test_weather.py", line 82, in testWeatherFindRemote
    self.assertEqual(str(today["Day"]), day)
AssertionError: 'Sun' != 'Mon'

----------------------------------------------------------------------
Ran 6 tests in 1.685s

FAILED (failures=1)
matt@eden:~/repo/sam/entertainerlib/tests$ date
Sun May 10 22:29:56 EDT 2009
matt@eden:~/repo/sam/entertainerlib/tests$ cat test_weather.py
# Copyright (c) 2009 Entertainer Developers - See COPYING - GPLv2
'''Tests Weather'''

from datetime import datetime, timedelta, tzinfo

from entertainerlib.tests import EntertainerTest
from entertainerlib.utils.weather import Weather

class WeatherTest(EntertainerTest):
    """
    WeatherTest class
    Tests for the weather module.
    """
    def setUp(self):
        """Sets up everything for the test"""
        EntertainerTest.setUp(self)

        self.weather = Weather("Bath,England")

    def tearDown(self):
        """Clean up after the test"""
        EntertainerTest.tearDown(self)

    def testWeatherFindRemote(self):
        """Tests the weather code using a call to the outside world"""
        class EnglandTimeZone(tzinfo):
            '''An implementation of tzinfo specific to England.'''
            def __init__(self):
                tzinfo.__init__(self)
                self.stdoffset = timedelta(hours=0)
                self.reprname = 'England'
                self.stdname = 'WET' # Western Europe Time
                self.dstname = 'BST' # British Summer Time

            def __repr__(self):
                return self.reprname

            def _first_sunday_on_or_after(self, dt):
                '''Figure out the DST date.'''
                days_to_go = 6 - dt.weekday()
                if days_to_go:
                    dt += timedelta(days_to_go)
                return dt

            def tzname(self, dt):
                '''See `tzinfo.tzname`.'''
                if self.dst(dt):
                    return self.dstname
                else:
                    return self.stdname

            def utcoffset(self, dt):
                '''See `tzinfo.utcoffset`.'''
                return self.stdoffset + self.dst(dt)

            def dst(self, dt):
                '''See `tzinfo.dst`.'''
                DSTSTART = datetime(1, 4, 1, 2)
                DSTEND = datetime(1, 10, 25, 1)
                ZERO = timedelta(0)
                HOUR = timedelta(hours=1)
                if dt is None or dt.tzinfo is None:
                    return ZERO
                assert dt.tzinfo is self

                start = self._first_sunday_on_or_after(
                    DSTSTART.replace(year=dt.year))
                end = self._first_sunday_on_or_after(
                    DSTEND.replace(year=dt.year))

                if start <= dt.replace(tzinfo=None) < end:
                    return HOUR
                else:
                    return ZERO
        england = EnglandTimeZone()

        self.weather.set_location('Bath,England')
        self.weather.refresh()
        forecasts = self.weather.get_forecasts()
        today = forecasts[0]
        day = datetime.now(england).strftime('%a')
        self.assertEqual(str(today["Day"]), day)
.
.
.
matt@eden:~/repo/sam/entertainerlib/tests$

Revision history for this message
Matt Layman (mblayman) wrote :

Paul, I'm assigning this to you because you have the most knowledge with this test and probably the best chance of fixing it. Plus, I know that it will probably piss you off to see this thing broken again so you'd probably be the most motivated to get it working too. :D

I didn't set it for 0.5 because I don't know how high a priority it should be in light of the other things that are being worked on.

Changed in entertainer:
assignee: nobody → Paul Hummer (rockstar)
importance: Undecided → Medium
status: New → Triaged
Revision history for this message
Samuel Buffet (samuel-buffet) wrote :

Test is running fine on my machine now but I had the same bug a few weeks ago.

Revision history for this message
Samuel Buffet (samuel-buffet) wrote :

Taking a closer look to the code I had an idea.

        england = EnglandTimeZone()

        self.weather.set_location('Bath,England')
        self.weather.refresh()
        forecasts = self.weather.get_forecasts()
        today = forecasts[0]
        day = datetime.now(england).strftime('%a')
        self.assertEqual(str(today["Day"]), day)

The error message is : AssertionError: 'Sun' != 'Mon'

So I think there's something wrong with EnglandTimeZone wich may give from time to time a result which is not perfectly accurate.

Paul Hummer (rockstar)
Changed in entertainer:
assignee: Paul Hummer (rockstar) → nobody
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.