Best Python code snippet using pandera_python
test_util_wspos.py
Source:test_util_wspos.py
1#!/usr/bin/env python32# -*- coding:utf-8 -*-3__author__ = 'Mu Yang <http://muyang.pro>'4__copyright__ = '2018-2020 CKIP Lab'5__license__ = 'GPL-3.0'6import pytest7from _base import _TestBase8from ckipnlp.container.util.wspos import *9from ckipnlp.container.seg import *10################################################################################################################################11class TestWsPosToken(_TestBase):12 obj_class = WsPosToken13 text_in = 'ä¸æå(Na)'14 list_in = [ 'ä¸æå', 'Na', ]15 dict_in = { 'word': 'ä¸æå', 'pos': 'Na', }16 def _assert_body(self, obj):17 assert obj.word == 'ä¸æå'18 assert obj.pos == 'Na'19 def test_str(self):20 obj = self.obj_class.from_text(self.text_in)21 assert str(obj) == self.text_in22################################################################################################################################23class TestWsPosSentence(_TestBase):24 obj_class = WsPosSentence25 test_io_list = NotImplemented26 test_io_dict = NotImplemented27 test_io_json = NotImplemented28 text_in = 'ä¸æå(Na)ãè¶(T)ãï¼(COMMACATEGORY)ãå(I)ãå(D)ãåå(D)ãã(PERIODCATEGORY)'29 def test_io_text(self):30 word_obj, pos_obj = self.obj_class.from_text(self.text_in)31 self._assert_body(word_obj, pos_obj)32 text_out = self.obj_class.to_text(word_obj, pos_obj)33 assert text_out, self.text_in34 def test_init(self):35 with pytest.raises(TypeError):36 obj = self.obj_class()37 def _assert_body(self, word_obj, pos_obj):38 assert isinstance(word_obj, SegSentence)39 assert len(word_obj) == 740 assert word_obj == [ 'ä¸æå', 'è¶', 'ï¼', 'å', 'å', 'åå', 'ã', ]41 assert isinstance(pos_obj, SegSentence)42 assert len(pos_obj) == 743 assert pos_obj == [ 'Na', 'T', 'COMMACATEGORY', 'I', 'D', 'D', 'PERIODCATEGORY', ]44################################################################################################################################45class TestWsPosParagraph(_TestBase):46 obj_class = WsPosParagraph47 test_io_list = NotImplemented48 test_io_dict = NotImplemented49 test_io_json = NotImplemented50 text_in = [51 'ä¸æå(Na)ãè¶(T)ãï¼(COMMACATEGORY)ãå(I)ãå(D)ãåå(D)ãã(PERIODCATEGORY)',52 'ã(PARENTHESISCATEGORY)ãå®è(VH)ãäº(T)ãï¼(EXCLAMATIONCATEGORY)ãã(PARENTHESISCATEGORY)ãï¼(COMMACATEGORY)ãç¢å¡ç´¢(Nb)ãä»(Nh)ãæ³(VE)',53 ]54 def test_io_text(self):55 word_obj, pos_obj = self.obj_class.from_text(self.text_in)56 self._assert_body(word_obj, pos_obj)57 text_out = self.obj_class.to_text(word_obj, pos_obj)58 assert text_out, self.text_in59 def test_init(self):60 with pytest.raises(TypeError):61 obj = self.obj_class()62 def _assert_body(self, word_obj, pos_obj):63 assert isinstance(word_obj, SegParagraph)64 assert len(word_obj) == 265 assert len(word_obj[0]) == 766 assert word_obj[0] == [ 'ä¸æå', 'è¶', 'ï¼', 'å', 'å', 'åå', 'ã', ]67 assert len(word_obj[1]) == 968 assert word_obj[1] == [ 'ã', 'å®è', 'äº', 'ï¼', 'ã', 'ï¼', 'ç¢å¡ç´¢', 'ä»', 'æ³', ]69 assert isinstance(pos_obj, SegParagraph)70 assert len(pos_obj) == 271 assert len(pos_obj[0]) == 772 assert pos_obj[0] == [ 'Na', 'T', 'COMMACATEGORY', 'I', 'D', 'D', 'PERIODCATEGORY', ]73 assert len(pos_obj[1]) == 9...
test_Taxonomy.py
Source:test_Taxonomy.py
1import os2import unittest3import taxidTools456current_path = os.path.dirname(__file__)7nodes = os.path.join(current_path, "data", "mininodes.dmp")8rankedlineage = os.path.join(current_path, "data", "minirankedlineage.dmp")91011class TestTaxdump(unittest.TestCase):12 13 def setUp(self):14 self.parent = taxidTools.Node(taxid = 0, name = "root", rank = "root", parent = None)15 self.child = taxidTools.Node(taxid = 1, name = "child", rank = "child", parent = self.parent)16 self.txd = taxidTools.Taxonomy({'0': self.parent, '1': self.child})17 18 def test_factory_dict(self):19 self.txd = taxidTools.Taxonomy({'0': self.parent, '1': self.child})20 self.assertEqual(len(self.txd.keys()), 2)21 22 def test_factory_add_node(self):23 self.txd = taxidTools.Taxonomy()24 self.txd.addNode(self.child)25 self.txd.addNode(self.parent)26 self.assertEqual(len(self.txd.keys()), 2)27 28 def test_factory_list(self):29 self.txd = taxidTools.Taxonomy.from_list([self.parent, self.child])30 self.assertEqual(len(self.txd.keys()), 2)31 32 def test_factory_taxdump(self):33 self.txd = taxidTools.Taxonomy.from_taxdump(nodes, rankedlineage)34 self.assertEqual(self.txd["9913"].parent.taxid, "9903")35 36 ancestry = taxidTools.Lineage(self.txd["9903"])37 self.assertEqual(len(ancestry), 29)38 self.assertEqual(ancestry[-1].taxid, "1")39 40 def test_IO_json(self):41 self.txd = taxidTools.Taxonomy.from_taxdump(nodes, rankedlineage)42 self.txd.write("test.json")43 self.reload = taxidTools.Taxonomy.from_json("test.json")44 45 ancestry = taxidTools.Lineage(self.reload["9903"])46 self.assertEqual(len(ancestry), 29)47 self.assertEqual(ancestry[-1].taxid, "1")48 49 self.txd.filterRanks(['genus', 'none'])50 self.txd.write("test2.json")51 test2 = taxidTools.load("test2.json")52 ancestry = taxidTools.Lineage(test2["9903"])53 self.assertIsInstance(ancestry[1], taxidTools.DummyNode)54 55 def test_getters(self):56 self.assertEqual(self.txd.getName(1), "child")57 self.assertEqual(self.txd.getRank(1), "child")58 self.assertEqual(self.txd.getParent(1).taxid, "0")59 60 def test_getAncestry(self):61 lin = self.txd.getAncestry(1)62 self.assertEqual(len(lin), 2)63 self.assertEqual(lin[0].taxid, "1")64 self.assertEqual(lin[1].taxid, "0")65 66 def test_ancestry_tests(self):67 self.assertTrue(self.txd.isAncestorOf(0,1))68 self.assertFalse(self.txd.isAncestorOf(1,0))69 self.assertFalse(self.txd.isAncestorOf(1,1))70 71 self.assertTrue(self.txd.isDescendantOf(1,0))72 self.assertFalse(self.txd.isDescendantOf(0,1))73 self.assertFalse(self.txd.isDescendantOf(1,1))
...
_base.py
Source:_base.py
...40 assert isinstance(obj, self.obj_class)41 self._assert_body(obj)42 dict_out = obj.to_dict()43 assert dict_out == self.dict_in44 def test_io_json(self):45 obj = self.obj_class.from_json(self.json_in)46 assert isinstance(obj, self.obj_class)47 self._assert_body(obj)48 json_out = obj.to_json(ensure_ascii=False)...
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!