def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) logging.basicConfig(format='%(asctime)s - %(levelname)s [%(filename)s:%(lineno)s %(funcName)20s] %(message)s', level=logging.INFO, handlers=[logging.StreamHandler()]) self.logger = logging.getLogger("vrnbus") self.tracker = EventTracker(logger, []) self.mock_provider = CdsTestDataProvider(logger) self.cds = CdsRequest(logger, self.mock_provider) self.processor = WebDataProcessor(self.cds, self.logger, self.tracker)
class CdsBusArrivalTestCases(unittest.TestCase): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) logging.basicConfig(format='%(asctime)s - %(levelname)s [%(filename)s:%(lineno)s %(funcName)20s] %(message)s', level=logging.INFO, handlers=[logging.StreamHandler()]) self.logger = logging.getLogger("vrnbus") self.tracker = EventTracker(logger, []) self.mock_provider = CdsTestDataProvider(logger) self.cds = CdsRequest(logger, self.mock_provider) self.processor = WebDataProcessor(self.cds, self.logger, self.tracker) def test_arrival(self): result = self.processor.get_arrival("про 49 5а", 51.692727, 39.18297) stops = result['bus_stops'] counts = 0 for k, v in stops.items(): self.logger.info(k) self.logger.info(v) counts += len(v.split('\n')) break self.logger.info(result) self.logger.info(counts) def test_businfo(self): result = self.processor.get_bus_info("про 49 5а", 51.692727, 39.18297, True) self.logger.info(result) def test_arrival_distance(self): src = 'Центральный автовокзал (в центр)' dst = 'Площадь Застава (в центр)' wrong_direction = self.cds.get_dist("27", dst, src) right_direction = self.cds.get_dist("27", src, dst) self.assertTrue(wrong_direction == 0) self.assertGreater(right_direction, 0) def test_arrival_by_id(self): for i in range(500): result = self.processor.get_arrival_by_id("pro", i) self.assertTrue(result['arrival_info']['found'])
format= '%(asctime)s.%(msecs)03d - %(levelname)s [%(filename)s:%(lineno)s %(funcName)10s] %(message)s', datefmt="%H:%M:%S", level=logging.INFO, handlers=[logging.StreamHandler(), file_handler]) logger = logging.getLogger("vrnbus") logger.info([{k: os.environ[k]} for (k) in os.environ if 'PATH' not in k]) LOAD_TEST_DATA = False try: import settings LOAD_TEST_DATA = settings.LOAD_TEST_DATA except ImportError: settings = None user_settings = {} if __name__ == "__main__": tracker = EventTracker(logger) data_provider = CdsTestDataProvider( logger) if LOAD_TEST_DATA else CdsDBDataProvider(logger) cds = CdsRequest(logger, data_provider) data_processor = WebDataProcessor(cds, logger) bot = BusBot(cds, user_settings, logger, tracker) application = BusSite(data_processor, logger, tracker) application.listen(os.environ.get('PORT', 8080)) tornado.ioloop.IOLoop.instance().start()