How to use test_docs method in SeleniumBase

Best Python code snippet using SeleniumBase

train_tokenizer_test.py

Source:train_tokenizer_test.py Github

copy

Full Screen

...37 @pytest.fixture(scope="class")38 def train_params(self):39 yield dict(save_tokenizer=False, show_progress=False)40 @pytest.fixture(scope="class")41 def test_docs(self):42 yield ["Dette er en dårlig <mask>.", "Test…"]43 def test_iterable_of_texts(44 self, dataset, valid_config_dict, train_params, test_docs45 ):46 config = TokenizerConfig(**valid_config_dict)47 tok = train_tokenizer(48 corpus=(s["text"] for s in dataset), config=config, **train_params49 )50 tokens = ["Det", "te", "er", "en", "dår", "lig", "<mask>", "."]51 assert tok.encode(test_docs[0]).tokens == tokens52 def test_list_of_texts(self, dataset, valid_config_dict, train_params, test_docs):53 config = TokenizerConfig(**valid_config_dict)54 tok = train_tokenizer(55 corpus=[s["text"] for s in dataset], config=config, **train_params...

Full Screen

Full Screen

test_leveldbindexer.py

Source:test_leveldbindexer.py Github

copy

Full Screen

1import os2import unittest3from shutil import rmtree4from gnes.indexer.doc.dict import DictIndexer5from gnes.indexer.doc.leveldb import LVDBIndexer6from gnes.proto import gnes_pb27from tests import txt_file2pb_docs8class TestBaseLVDB(unittest.TestCase):9 def setUp(self):10 dirname = os.path.dirname(__file__)11 self.test_docs = txt_file2pb_docs(open(os.path.join(dirname, 'tangshi.txt'), encoding='utf8'))12 self.db_path = './test_leveldb'13 self.dump_path = os.path.join(dirname, 'indexer.bin')14 self.dump_yaml_path = os.path.join(dirname, 'indexer.yaml')15 def tearDown(self):16 if os.path.exists(self.db_path):17 rmtree(self.db_path)18 if os.path.exists(self.dump_path):19 os.remove(self.dump_path)20 if os.path.exists(self.dump_yaml_path):21 os.remove(self.dump_yaml_path)22 if os.path.exists('my-indexer-531.bin'):23 os.remove('my-indexer-531.bin')24 if os.path.exists('my-indexer-531.yml'):25 os.remove('my-indexer-531.yml')26 def test_dict_indexer(self):27 db = DictIndexer()28 db.add(range(len(self.test_docs)), self.test_docs)29 db.dump(self.dump_path)30 self.assertEqual(len(self.test_docs), db.num_docs)31 db2 = DictIndexer.load(self.dump_path)32 self.assertEqual(len(self.test_docs), db2.num_docs)33 db.name = 'my-indexer-531'34 db.dump()35 db.dump_yaml()36 db3 = DictIndexer.load_yaml(db.yaml_full_path)37 for k in db3.query([1, 2, 3]):38 self.assertIsInstance(k, gnes_pb2.Document)39 self.assertEqual(len(self.test_docs), db3.num_docs)40 def test_add_docs(self):41 db = LVDBIndexer(self.db_path)42 db.add(range(len(self.test_docs)), self.test_docs)43 self.assertTrue(os.path.exists(self.db_path))44 self.assertLess(0, len(os.listdir(self.db_path)))45 db.close()46 def test_query(self):47 db = LVDBIndexer(self.db_path)48 db.add(range(len(self.test_docs)), self.test_docs)49 res1 = db.query(range(len(self.test_docs)))50 num_non_empty = sum(1 for d in res1 if d)51 self.assertEqual(num_non_empty, len(self.test_docs))52 res2 = db.query(range(len(self.test_docs) + 1, len(self.test_docs) + 100))53 num_non_empty = sum(1 for d in res2 if d)54 self.assertEqual(num_non_empty, 0)55 db.close()56 def dump_load(self):57 tmp = LVDBIndexer(self.db_path)58 tmp.add(range(len(self.test_docs)), self.test_docs)59 tmp.dump(self.dump_path)60 tmp.close()61 db = LVDBIndexer.load(self.db_path)62 res1 = db.query(range(len(self.test_docs)))63 num_non_empty = sum(1 for d in res1 if d)64 self.assertEqual(num_non_empty, self.test_data1.length)65 res2 = db.query(range(len(self.test_docs) + 1, len(self.test_docs) + 100))66 num_non_empty = sum(1 for d in res2 if d)67 self.assertEqual(num_non_empty, 0)...

Full Screen

Full Screen

test_leveldbindexerasync.py

Source:test_leveldbindexerasync.py Github

copy

Full Screen

1import os2import unittest3from shutil import rmtree4from gnes.indexer.doc.leveldb import AsyncLVDBIndexer5from tests import txt_file2pb_docs6class TestBaseLVDB(unittest.TestCase):7 def setUp(self):8 dirname = os.path.dirname(__file__)9 self.test_docs = txt_file2pb_docs(open(os.path.join(dirname, 'tangshi.txt')))10 self.query_hit_id = list(range(len(self.test_docs)))11 self.query_miss_id = list(range(len(self.test_docs) + 1, len(self.test_docs) + 100))12 self.db_path = './test_leveldb'13 self.dump_path = os.path.join(dirname, 'indexer.bin')14 def tearDown(self):15 if os.path.exists(self.db_path):16 rmtree(self.db_path)17 def test_add_uni(self):18 db = AsyncLVDBIndexer(self.db_path)19 db.add(range(len(self.test_docs)), self.test_docs)20 self.assertTrue(os.path.exists(self.db_path))21 self.assertLess(0, len(os.listdir(self.db_path)))22 db.close()23 def test_add_multi(self):24 db = AsyncLVDBIndexer(self.db_path)25 db.add(range(len(self.test_docs)), self.test_docs)26 self.assertTrue(os.path.exists(self.db_path))27 self.assertLess(0, len(os.listdir(self.db_path)))28 db.close()29 @unittest.SkipTest30 def test_query(self):31 db = AsyncLVDBIndexer(self.db_path)32 db.add(range(len(self.test_docs)), self.test_docs)33 res1 = db.query(self.query_hit_id)34 num_non_empty = sum(1 for d in res1 if d)35 self.assertEqual(num_non_empty, len(self.test_docs))36 res2 = db.query(self.query_miss_id)37 num_non_empty = sum(1 for d in res2 if d)38 self.assertEqual(num_non_empty, 0)39 db.close()40 def dump_load(self):41 tmp = AsyncLVDBIndexer(self.db_path)42 tmp.add(range(len(self.test_docs)), self.test_docs)43 tmp.dump(self.dump_path)44 tmp.close()45 db = AsyncLVDBIndexer.load(self.db_path)46 res1 = db.query(self.query_hit_id)47 num_non_empty = sum(1 for d in res1 if d)48 self.assertEqual(num_non_empty, len(self.test_docs))49 res2 = db.query(self.query_miss_id)50 num_non_empty = sum(1 for d in res2 if d)51 self.assertEqual(num_non_empty, 0)...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run SeleniumBase automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful