mirror of
https://github.com/SpudGunMan/meshing-around.git
synced 2026-03-28 17:32:36 +01:00
testing weather replacement funciton so it can be re-worked
This commit is contained in:
@@ -101,7 +101,17 @@ def get_weather(lat=0, lon=0, unit=0):
|
||||
# extract data from rows
|
||||
for row in rows:
|
||||
# shrink the text
|
||||
line = row.text.replace("Monday", "Mon ") \
|
||||
line = replace_weather(row.text)
|
||||
# only grab a few days of weather
|
||||
if len(weather.split("\n")) < DAYS_OF_WEATHER:
|
||||
weather += line + "\n"
|
||||
# trim off last newline
|
||||
weather = weather[:-1]
|
||||
|
||||
return weather
|
||||
|
||||
def replace_weather(row):
|
||||
line = row.replace("Monday", "Mon ") \
|
||||
.replace("Tuesday", "Tue ") \
|
||||
.replace("Wednesday", "Wed ") \
|
||||
.replace("Thursday", "Thu ") \
|
||||
@@ -130,10 +140,5 @@ def get_weather(lat=0, lon=0, unit=0):
|
||||
.replace("precipitation", "precip") \
|
||||
.replace("showers", "shwrs") \
|
||||
.replace("thunderstorms", "t-storms")
|
||||
# only grab a few days of weather
|
||||
if len(weather.split("\n")) < DAYS_OF_WEATHER:
|
||||
weather += line + "\n"
|
||||
# trim off last newline
|
||||
weather = weather[:-1]
|
||||
|
||||
return weather
|
||||
|
||||
return line
|
||||
|
||||
@@ -38,7 +38,45 @@ class TestGetWeather(unittest.TestCase):
|
||||
print(f"tide: {tide}")
|
||||
self.assertNotEqual(tide, NO_DATA_NOGPS)
|
||||
self.assertNotEqual(tide, ERROR_FETCHING_DATA)
|
||||
|
||||
def test_replace_weather(self):
|
||||
# Test replacing days of the week
|
||||
self.assertEqual(replace_weather("Monday"), "Mon ")
|
||||
self.assertEqual(replace_weather("Tuesday"), "Tue ")
|
||||
self.assertEqual(replace_weather("Wednesday"), "Wed ")
|
||||
self.assertEqual(replace_weather("Thursday"), "Thu ")
|
||||
self.assertEqual(replace_weather("Friday"), "Fri ")
|
||||
self.assertEqual(replace_weather("Saturday"), "Sat ")
|
||||
|
||||
# Test replacing time periods
|
||||
self.assertEqual(replace_weather("Today"), "Today ")
|
||||
self.assertEqual(replace_weather("Tonight"), "Tonight ")
|
||||
self.assertEqual(replace_weather("Tomorrow"), "Tomorrow ")
|
||||
self.assertEqual(replace_weather("This Afternoon"), "Afternoon ")
|
||||
|
||||
# Test replacing directions
|
||||
self.assertEqual(replace_weather("northwest"), "NW")
|
||||
self.assertEqual(replace_weather("northeast"), "NE")
|
||||
self.assertEqual(replace_weather("southwest"), "SW")
|
||||
self.assertEqual(replace_weather("southeast"), "SE")
|
||||
self.assertEqual(replace_weather("north"), "N")
|
||||
self.assertEqual(replace_weather("south"), "S")
|
||||
self.assertEqual(replace_weather("east"), "E")
|
||||
self.assertEqual(replace_weather("west"), "W")
|
||||
self.assertEqual(replace_weather("Northwest"), "NW")
|
||||
self.assertEqual(replace_weather("Northeast"), "NE")
|
||||
self.assertEqual(replace_weather("Southwest"), "SW")
|
||||
self.assertEqual(replace_weather("Southeast"), "SE")
|
||||
self.assertEqual(replace_weather("North"), "N")
|
||||
self.assertEqual(replace_weather("South"), "S")
|
||||
self.assertEqual(replace_weather("East"), "E")
|
||||
self.assertEqual(replace_weather("West"), "W")
|
||||
|
||||
# Test replacing weather terms
|
||||
self.assertEqual(replace_weather("precipitation"), "precip")
|
||||
self.assertEqual(replace_weather("showers"), "shwrs")
|
||||
self.assertEqual(replace_weather("thunderstorms"), "t-storms")
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user