def test_search_events(self, d: date, expected_events: [Event]): actual_events = events.search_events(d) self.assertEqual( len(expected_events), len(actual_events), 'Expected %d elements, got %d for date %s.' % (len(expected_events), len(actual_events), d.isoformat())) for i, expected_event in enumerate(expected_events): actual_event = actual_events[i] # Remove unnecessary precision (seconds and microseconds) actual_event.start_time = datetime(actual_event.start_time.year, actual_event.start_time.month, actual_event.start_time.day, actual_event.start_time.hour, actual_event.start_time.minute) self.assertEqual(expected_event.__dict__, actual_event.__dict__)
def test_get_events_raises_exception_on_out_of_date_range(self): with self.assertRaises(OutOfRangeDateError): events.search_events(date(1789, 5, 5))
def main(): environment = core.get_env() output_formats = get_dumpers() args = get_args(list(output_formats.keys())) if args.special_action is not None: return 0 if args.special_action() else 1 try: compute_date = get_date(args.date) except ValueError as error: print(colored(error.args[0], color='red', attrs=['bold'])) return -1 position = None if args.latitude is not None or args.longitude is not None: position = Position(args.latitude, args.longitude) elif environment.latitude is not None and environment.longitude is not None: position = Position(float(environment.latitude), float(environment.longitude)) if args.format == 'pdf': print(_('Save the planet and paper!\n' 'Consider printing you PDF document only if really necessary, and use the other side of the sheet.')) if position is None: print() print(colored(_("PDF output will not contain the ephemerides, because you didn't provide the observation " "coordinate."), 'yellow')) try: ephemeris = EphemeridesComputer(position) ephemerides = ephemeris.compute_ephemerides(compute_date) events_list = events.search_events(compute_date) timezone = args.timezone if timezone is None and environment.timezone is not None: timezone = int(environment.timezone) elif timezone is None: timezone = 0 selected_dumper = output_formats[args.format](ephemerides, events_list, date=compute_date, timezone=timezone, with_colors=args.colors) output = selected_dumper.to_string() except UnavailableFeatureError as error: print(colored(error.msg, 'red')) return 2 if args.output is not None: try: with open(args.output, 'wb') as output_file: output_file.write(output) except OSError as error: print(_('Could not save the output in "{path}": {error}').format(path=args.output, error=error.strerror)) elif not selected_dumper.is_file_output_needed(): print(output) else: print(colored(_('Selected output format needs an output file (--output).'), color='red')) return 1 return 0