Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_035_parseTime_suppress_auto_month():
"""Check that explicit month suppresses automatic month rollback."""
next_day = tomorrow.day
if next_day > today.day:
last_year = today.year - 1
timestr = "%02d1651Z" % (next_day)
report = Metar.Metar("KEWR " + timestr, month=1)
assert report.decode_completed
assert report.time.day == next_day
assert report.time.month == 1
if today.month > 1:
assert report.time.year == today.year
else:
assert report.time.year == last_year
def test_020_parseStation_legal():
"""Check parsing of the station code."""
assert Metar.Metar("KEWR").station_id == "KEWR"
assert Metar.Metar("METAR KEWR").station_id == "KEWR"
assert Metar.Metar("METAR COR KEWR").station_id == "KEWR"
assert Metar.Metar("BIX1").station_id == "BIX1"
assert Metar.Metar("K256").station_id == "K256"
def test_020_parseStation_legal():
"""Check parsing of the station code."""
assert Metar.Metar("KEWR").station_id == "KEWR"
assert Metar.Metar("METAR KEWR").station_id == "KEWR"
assert Metar.Metar("METAR COR KEWR").station_id == "KEWR"
assert Metar.Metar("BIX1").station_id == "BIX1"
assert Metar.Metar("K256").station_id == "K256"
def report_nowind(vis_group):
"""(Macro) Return Metar object for a report containing the given
visibility group, without a preceeding wind group.
"""
return Metar.Metar(sta_time + vis_group)
def report(vis_group):
"""(Macro) Return Metar object for a report given visibility group."""
return Metar.Metar(sta_time + "09010KT " + vis_group)
def report(runway_state):
"""(Macro) Return Metar object for given runway state group"""
sample_metar = (
"EGNX 191250Z VRB03KT 9999 -RASN FEW008 SCT024 " "BKN046 M01/M03 Q0989 "
)
return Metar.Metar(sample_metar + " " + runway_state)
def test_031_parseTime_specify_year():
"""Check that the year can be specified."""
other_year = 2003
report = Metar.Metar("KEWR 101651Z", year=other_year)
assert report.decode_completed
assert report.time.year == other_year
def report(vis_group):
"""(Macro) Return Metar object for a report with the vis group."""
return Metar.Metar(sta_time + "09010KT " + vis_group)
def test_error_checking():
"""Test exception raising."""
with pytest.raises(ValueError):
distance("10SM")
with pytest.raises(ValueError):
distance("M1/2SM")
with pytest.raises(ValueError):
distance("1000", "M", "=")
with pytest.raises(ValueError):
distance("1000", "M", "gt")
with pytest.raises(UnitsError):
distance("10", "NM")
with pytest.raises(UnitsError):
distance(distance("1000").value, "furlongs")
with pytest.raises(UnitsError):
distance(distance("500").string, "yards")
def test_defaults():
"""Test defaults for units."""
assert distance("10").value() == 10.0
assert distance("1000").value("M") == 1000.0
assert distance("1500").string() == "1500 meters"
assert distance("1500", None).string() == "1500 meters"
assert distance("5", "SM").string() == "5 miles"