def test_execution_time(self): enable_socket() text_and_time = OcrTable(self.image_path, show_performace=True) has_time = text_and_time.execution_time and \ text_and_time.show_performace and \ len(ast.literal_eval(repr(text_and_time))) > 1 self.assertTrue(has_time)
def socket_enabled(pytestconfig): """Enable socket.socket for duration of this test function. This incorporates changes from https://github.com/miketheman/pytest-socket/pull/76 and hardcodes allow_unix_socket to True because it's not passed on the command line. """ socket_was_disabled = socket.socket != pytest_socket._true_socket pytest_socket.enable_socket() yield if socket_was_disabled: disable_socket(allow_unix_socket=True)
def test_loadBioNLP_fail(): pytest_socket.disable_socket() with pytest.raises(RuntimeError) as excinfo: corpus = kindred.bionlpst.load('2016-BB3-event-train') pytest_socket.enable_socket() assert excinfo.value.args == ('A test tried to use socket.socket.', )
def test_get_model(self): enable_socket() if os.path.isfile(self.model_path): os.remove(self.model_path) model = aux.get_model_from_s3(self.model_path) self.assertTrue(isinstance(model, str))
def test_load_model(self): enable_socket() model = aux.load_east_model() self.assertTrue(isinstance(model, str))
def test_url_type(self): enable_socket() url = 'https://img.icons8.com/all/500/general-ocr.png' input_type = aux.get_input_type(url) self.assertEqual(input_type, 1)
def test_image_processing(self): enable_socket() image = Image.open(self.image_path) text = OcrTable(image) type_output = isinstance(text.text, str) self.assertTrue(type_output)
def test_url_processing(self): enable_socket() text = OcrTable('https://project-elements-nk.s3.amazonaws.com/ocr.png') type_output = isinstance(text.text, str) self.assertTrue(type_output)
def reenable_socket(): # The tests can leave the socket disabled in the global scope. # Fix that by automatically re-enabling it after each test yield enable_socket()
def pytest_enable_socket(): enable_socket()