def tz_args_strat(allow_naive, tz_list, name): if tz_list is None: tz_strat = timezones_strategy() else: tz_strat = st.sampled_from([ tz if isinstance(tz, dt.tzinfo) else pytz.timezone(tz) for tz in tz_list ]) if allow_naive or (allow_naive is None and tz_strat.is_empty): tz_strat = st.none() | tz_strat if tz_strat.is_empty: raise InvalidArgument( 'Cannot create non-naive %s with no timezones allowed.' % name) return tz_strat