@@ -486,6 +486,51 @@ def _paris_tzif_bytes() -> bytes:
486486 return resources .files ("tzdata.zoneinfo" ).joinpath ("Europe" , "Paris" ).read_bytes ()
487487
488488
489+ def _new_york_tzif_bytes () -> bytes :
490+ from importlib import resources
491+
492+ return (
493+ resources .files ("tzdata.zoneinfo" ).joinpath ("America" , "New_York" ).read_bytes ()
494+ )
495+
496+
497+ def test_from_file_timezones_with_different_bytes_are_not_equal ():
498+ # Two keyless Timezones built from different zone files must not compare
499+ # equal: before this fix, __eq__ only looked at the key, which is None for
500+ # both, so any two from_file() timezones collapsed into one.
501+ from io import BytesIO
502+
503+ import pendulum .tz .timezone as timezone_module
504+
505+ paris = timezone_module .Timezone .from_file (BytesIO (_paris_tzif_bytes ()))
506+ new_york = timezone_module .Timezone .from_file (BytesIO (_new_york_tzif_bytes ()))
507+
508+ assert paris .key is None
509+ assert new_york .key is None
510+ assert paris != new_york
511+ assert hash (paris ) != hash (new_york )
512+ assert len ({paris , new_york }) == 2
513+
514+ # A keyless instance still never equals a named one.
515+ assert paris != timezone_module .Timezone ("Europe/Paris" )
516+
517+
518+ def test_from_file_timezones_with_same_bytes_are_equal ():
519+ from io import BytesIO
520+
521+ import pendulum .tz .timezone as timezone_module
522+
523+ first = timezone_module .Timezone .from_file (BytesIO (_paris_tzif_bytes ()))
524+ second = timezone_module .Timezone .from_file (BytesIO (_paris_tzif_bytes ()))
525+
526+ assert first == second
527+ assert hash (first ) == hash (second )
528+ assert len ({first , second }) == 1
529+
530+ # Equality survives a pickle round-trip.
531+ assert pickle .loads (pickle .dumps (first )) == first
532+
533+
489534def test_from_file_without_a_key_can_be_pickled ():
490535 # get_local_timezone()'s last-resort fallback builds a Timezone this same way, with no key.
491536 from io import BytesIO
0 commit comments