How to use assertSameElements method in autotest

Best Python code snippet using autotest_python

sblist_test.py

Source:sblist_test.py Github

copy

Full Screen

...18import server19import util20import unittest21class ListTest(unittest.TestCase):22 def assertSameElements(self, a, b):23 a = sorted(list(a))24 b = sorted(list(b))25 self.assertEqual(a, b, 'Expected: [%s], Found: [%s]' %26 (', '.join(map(str, a)), ', '.join(map(str, b))))27 def setUp(self):28 self._list = sblist.List('goog-malware-shavar')29 self._list.AddPrefix('aprefix', 1)30 self._list.AddPrefix('bprefix', 2)31 self._list.AddPrefix('aprefix', 3)32 self._list.AddPrefix('cprefix', 1)33 self._list.AddPrefix('0000', 4)34 self.assertTrue(self._list.AddFullHash('0000fullhash', 4, 10))35 self._list.AddPrefix('dprefix', 5)36 self._list.AddEmptyAddChunk(5) # should remove dprefix37 self._list.AddPrefix('eprefix', 6)38 self._list.AddPrefix('fprefix', 6)39 # After this add chunk 6 should still be around40 self.assertTrue(self._list.RemovePrefix('eprefix', 1, 6))41 self._list.AddPrefix('gprefix', 7)42 self._list.AddPrefix('hprefix', 8)43 self.assertTrue(self._list.RemovePrefix('gprefix', 2, 7))44 self.assertTrue(self._list.RemovePrefix('hprefix', 2, 8))45 # Subs for adds we have not yet received.46 self.assertFalse(self._list.RemovePrefix('iprefix', 2, 11))47 self.assertFalse(self._list.RemovePrefix('jprefix', 2, 12))48 # Test prefix matching49 self._list.AddPrefix('prefixaa', 9)50 self._list.AddPrefix('prefixab', 9)51 self._list.AddPrefix('prefixaa', 10)52 self._list.AddEmptySubChunk(3)53 # Add some empty sub chunks to see that we would support fragmentation.54 self._list.AddEmptySubChunk(5)55 self._list.AddEmptySubChunk(6)56 self._list.AddEmptySubChunk(7)57 def testGetRangeStr(self):58 sbl = sblist.List('foo')59 s = sbl._GetRangeStr([1, 2, 3, 4])60 self.assertEqual(s, '1-4')61 s = sbl._GetRangeStr([1, 2, 4, 5, 7, 8, 9, 10, 11, 13, 15, 17])62 self.assertEqual(s, '1-2,4-5,7-11,13,15,17')63 s = sbl._GetRangeStr([1])64 self.assertEqual(s, '1')65 def testName(self):66 self.assertEqual('goog-malware-shavar', self._list.Name())67 def testGetSetUpdateTime(self):68 self.assertEqual(None, self._list.UpdateTime())69 self._list.SetUpdateTime(42)70 self.assertEqual(42, self._list.UpdateTime())71 def testAddChukMap(self):72 self.assertSameElements([1, 2, 3, 4, 5, 6, 7, 8, 9, 10],73 self._list.AddChunkMap())74 self.assertSameElements(['aprefix', 'cprefix'],75 self._list.AddChunkMap()[1])76 self.assertSameElements(['bprefix',], self._list.AddChunkMap()[2])77 self.assertSameElements(['aprefix',], self._list.AddChunkMap()[3])78 self.assertSameElements(['0000',], self._list.AddChunkMap()[4])79 self.assertSameElements([], self._list.AddChunkMap()[5])80 self.assertSameElements(['fprefix',], self._list.AddChunkMap()[6])81 self.assertSameElements([], self._list.AddChunkMap()[7])82 self.assertSameElements([], self._list.AddChunkMap()[8])83 self.assertSameElements(['prefixaa', 'prefixab'],84 self._list.AddChunkMap()[9])85 self.assertSameElements(['prefixaa'], self._list.AddChunkMap()[10])86 def testSubChunkMap(self):87 self.assertSameElements([1, 2, 3, 5, 6, 7],88 self._list.SubChunkMap())89 self.assertEqual(0, len(self._list.SubChunkMap()[1]))90 self.assertSameElements([sblist.SubEntry('iprefix', 2, 11),91 sblist.SubEntry('jprefix', 2, 12)],92 self._list.SubChunkMap()[2])93 self.assertSameElements([], self._list.SubChunkMap()[3])94 self.assertSameElements([], self._list.SubChunkMap()[5])95 self.assertSameElements([], self._list.SubChunkMap()[6])96 self.assertSameElements([], self._list.SubChunkMap()[7])97 def testNumPrefixes(self):98 self.assertEqual(9, self._list.NumPrefixes())99 def testGotAddChunk(self):100 for i in [1, 2, 3, 4, 5, 6, 7]:101 self.assertTrue(self._list.GotAddChunk(i))102 self.assertFalse(self._list.GotAddChunk(100))103 def testGotSubChunk(self):104 for i in [1, 2, 3, 5, 6, 7]:105 self.assertTrue(self._list.GotSubChunk(i))106 self.assertFalse(self._list.GotSubChunk(4))107 def testAddFullHash(self):108 # The prefix must be present in the list.109 self.assertFalse(self._list.AddFullHash('noprefix', 4, 10))110 self.assertTrue(self._list.AddFullHash('0000full', 4, 42))111 entry = sblist.AddEntry('0000', 4, '0000full')112 self.assertSameElements([entry], self._list.GetPrefixMatches('0000'))113 def testAddPrefix(self):114 # This should return false because this add chunk is already subbed.115 self.assertFalse(self._list.AddPrefix('iprefix', 11))116 # Test adding a prefix to a new chunk.117 self.assertTrue(self._list.AddPrefix('asdf', 10))118 entry = sblist.AddEntry('asdf', 10)119 self.assertSameElements([entry], self._list.GetPrefixMatches('asdfasdf'))120 self.assertSameElements([entry], self._list.GetPrefixMatches('asdf'))121 # Test adding a prefix to an existing chunk.122 self.assertTrue(self._list.AddPrefix('asdfasdf', 3))123 other_entry = sblist.AddEntry('asdfasdf', 3)124 self.assertSameElements([entry, other_entry],125 self._list.GetPrefixMatches('asdfasdf'))126 # Check to see if it supports full hashes correctly.127 fullhash = util.GetHash256('asdf')128 self.assertTrue(self._list.AddPrefix(fullhash, 11))129 self.assertEqual(1, len(list(self._list.GetPrefixMatches(fullhash))))130 def testRemovePrefix(self):131 # Can't remove non existent prefix.132 self.assertFalse(self._list.RemovePrefix('some_prefix', 8, 1))133 # Remove first of two prefixes.134 self.assertTrue(self._list.RemovePrefix('aprefix', 8, 1))135 entry = sblist.AddEntry('aprefix', 3)136 self.assertSameElements([entry], self._list.GetPrefixMatches('aprefix'))137 # Remove second prefix.138 self.assertTrue(self._list.RemovePrefix('aprefix', 8, 3))139 self.assertSameElements([], self._list.GetPrefixMatches('aprefix'))140 def testDeleteAddChunk(self):141 # Delete add chunk that does not exist.142 self.assertFalse(self._list.DeleteAddChunk(11))143 # Delete empty add chunk144 self.assertTrue(self._list.DeleteAddChunk(5))145 self.assertFalse(self._list.GotAddChunk(5))146 self.assertSameElements([], self._list.GetPrefixMatches('dprefix'))147 # Delete normal add chunk148 self.assertTrue(self._list.DeleteAddChunk(1))149 self.assertFalse(self._list.GotAddChunk(1))150 entry = sblist.AddEntry('aprefix', 3)151 self.assertSameElements([entry], self._list.GetPrefixMatches('aprefix'))152 self.assertSameElements([], self._list.GetPrefixMatches('cprefix'))153 def testDeleteSubChunk(self):154 # Delete sub chunk that does not exist.155 self.assertFalse(self._list.DeleteSubChunk(8))156 # Delete empty sub chunk.157 self.assertTrue(self._list.DeleteSubChunk(7))158 self.assertFalse(self._list.GotSubChunk(7))159 # Delete non-empty sub chunk160 self.assertTrue(self._list.DeleteSubChunk(2))161 self.assertFalse(self._list.GotSubChunk(2))162 def testDownloadRequest(self):163 self.assertEqual('goog-malware-shavar;a:1-10:s:1-3,5-7',164 self._list.DownloadRequest(False))165 self.assertEqual('goog-malware-shavar;a:1-10:s:1-3,5-7:mac',166 self._list.DownloadRequest(True))167 # Make sure that this works properly on an empty list as well168 list = sblist.List("empty-testing-list")169 self.assertEqual('empty-testing-list;', list.DownloadRequest(False))170 self.assertEqual('empty-testing-list;mac', list.DownloadRequest(True))171 def testGetPrefixMatches(self):172 self.assertSameElements([self._list.AddChunkMap()[9]['prefixaa'],173 self._list.AddChunkMap()[10]['prefixaa']],174 self._list.GetPrefixMatches('prefixaa'))175 self.assertSameElements([self._list.AddChunkMap()[9]['prefixaa'],176 self._list.AddChunkMap()[10]['prefixaa']],177 self._list.GetPrefixMatches('prefixaaasdfasdf'))178 self.assertSameElements([], self._list.GetPrefixMatches('prefixa'))179 self.assertSameElements([self._list.AddChunkMap()[9]['prefixab']],180 self._list.GetPrefixMatches('prefixabasdasdf'))181class SubEntryTest(unittest.TestCase):182 def testAccessors(self):183 entry = sblist.SubEntry('hash_prefix', 1, 2)184 self.assertEqual('hash_prefix', entry.Prefix())185 self.assertEqual(1, entry.SubNum())186 self.assertEqual(2, entry.AddNum())187class AddEntryTest(unittest.TestCase):188 def testSimple(self):189 # Test with no full-hash.190 entry = sblist.AddEntry('prefix', 1)191 self.assertEqual('prefix', entry.Prefix())192 self.assertEqual(None, entry.FullHash())193 self.assertEqual(None, entry.GetHashTimestamp())...

Full Screen

Full Screen

chatspeak_test.py

Source:chatspeak_test.py Github

copy

Full Screen

...43 "testdata/chatspeak_lexicon.tsv"))44 def testDeduplicator(self):45 def expand_string(s: str) -> List[str]:46 return rewrite.lattice_to_strings(self.deduplicator.expand(s))47 self.assertSameElements(expand_string("cooooool"), ["cool", "col"])48 self.assertSameElements(49 expand_string("coooooooooooooooollllllllll"), ["cool", "col"])50 self.assertSameElements(expand_string("chicken"), [])51 def testDeabbreviator(self):52 def expand_string(s: str) -> List[str]:53 return rewrite.lattice_to_strings(self.deabbreviator.expand(s))54 self.assertSameElements(expand_string("wrthg"), ["warthog"])55 self.assertSameElements(expand_string("wthg"), ["warthog"])56 self.assertSameElements(expand_string("z"), [])57 def testRegexps(self):58 def expand_string(s: str) -> List[str]:59 return rewrite.lattice_to_strings(self.regexps.expand(s))60 result = expand_string("delish")61 self.assertSameElements(result, ["delicious"])62 result = expand_string("kooooooooool")63 self.assertSameElements(result, ["cool"])64 result = expand_string("zomgggggggg")65 self.assertSameElements(result, ["oh my god"])66 def testLexicon(self):67 def expand_string(s: str) -> List[str]:68 return rewrite.lattice_to_strings(self.lexicon.expand(s))69 self.assertSameElements(expand_string("1nam"), ["one in a million"])70if __name__ == "__main__":...

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 autotest 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