Best Python code snippet using tox_python
__init__.py
Source: __init__.py
...68 heapq.heappush(trees, parent)69 self.tree = trees[0]70 def encoder(self):71 "get decoder instance"72 return HuffEncoder(HuffTree._getdict(self.tree))73 def decoder(self):74 "get decoder instance"75 return HuffDecoder(HuffTree._flatten(self.tree))76 @staticmethod77 def _getdict(huffTree,bits=BitArray()):78 if len(huffTree) == 2:79 yield huffTree[1],bits80 else:81 for ix,h in enumerate(huffTree[1:3]):82 for y in HuffTree._getdict(h,bits+(ix,)):83 yield y84 85 @staticmethod86 def _flatten(huffTree):87 assert len(huffTree) > 288 l = []89 for h in huffTree[1:3]:90 if len(h) == 2:91 l.append(0)92 l.append(h[1])93 else:94 t = HuffTree._flatten(h)95 l.append(len(t))96 l += t...
hash_demo.py
Source: hash_demo.py
1#coding=utf-82'''3Created on 2016-7-3145@author: kemin.yu6'''78num = 69factor = 210#table = [None] * num*factor11size = 10012table = [None] * size1314def _print_table():15 print "====== table ======"16 line1 = line2 = ""17 for i in range(size):18 line1 += " %4s ," % i19 if table[i] is None:20 line2 += " %4s ," % ""21 else:22 line2 += " %4s ," % table[i]23 if (i+1) % 20 == 0:24 print line125 print line226 print "--------------------"27 line1 = line2 = ""2829def _getDict(n):30 import random31 result = {}32 for i in range(n):33 k = random.randint(0, n*factor-1)34 result[k] = str(i)35 return result36 37# hash(k, v)38# t: table39# k: int40# v: str4142# ç´æ¥å®åæ³ 43def hash1(k, v, t):44 t[k] = v45 46def demo1():47 d = _getDict(num)48 for k, v in d.items():49 hash1(k, v, table)50 print sorted(d.items())51 _print_table()52 53def hash1b(k, v, t):54 def linear(a, b):55 return a*k+b56 t[linear(2, 3)] = v57 58def demo1b():59 d = _getDict(num)60 for k, v in d.items():61 hash1b(k, v, table)62 print sorted(d.items())63 _print_table()6465#æ°ååææ³66# å¹³æ¹åä¸67def hash2(k, v, t):68 index = k * k / 100 % 10069 t[index] = v70 71def demo2():72 d = {1123: "zero", 2356: "mike", 3921: "john"}73 for k, v in d.items():74 hash2(k, v, table)75 print sorted(d.items())76 _print_table()77 78# æå æ³79def hash2b(k, v, t):80 rest = k;81 sum = 082 while rest > 100:83 sum += rest % 10084 rest = rest / 10085 sum += rest86 sum %= 10087 t[sum] = v88 89def demo2b():90 d = {11234578: "zero", 23212356: "mike", 39215672: "john"}91 for k, v in d.items():92 hash2b(k, v, table)93 print sorted(d.items())94 _print_table()95 96# é¤çä½æ°æ³97def hash2c(k, v, t):98 t[k%100] = v99 100def demo2c():101 d = {11234578: "zero", 23212356: "mike", 39215672: "john"}102 for k, v in d.items():103 hash2c(k, v, table)104 print sorted(d.items())105 _print_table()106 107# éæºæ°æ³108def hash2d(k, v, t):109 import random110 t[random.randint(0, 99)] = v111 112def demo2d():113 d = _getDict(num)114 for k, v in d.items():115 hash2d(k, v, table)116 print sorted(d.items())117 _print_table()118119def demo():120 d = _getDict(10)121 print d, len(d)122 print table123 _print_table()124125if __name__ == '__main__':126 demo2d()
...
test_peak_validation.py
Source: test_peak_validation.py
1# flake8: noqa2import unittest3import pytest4from lmfit import Model5import raman_fitting6from raman_fitting.deconvolution_models.peak_validation import (7 NotFoundAnyModelsWarning,8 PeakModelValidator,9)10class TestPeakModelValidator(unittest.TestCase):11 def setUp(self):12 self.pmv = PeakModelValidator()13 def test_pmv_valid_models(self):14 self.assertTrue(self.pmv.valid_models)15 def test_pmv_set_debug(self):16 self.assertFalse(self.pmv.debug)17 self.assertTrue(self.pmv._set_debug(**{"debug": True}))18 def test_get_subclasses_from_base(self):19 with self.assertWarns(NotFoundAnyModelsWarning):20 self.pmv.get_subclasses_from_base("")21 with self.assertWarns(NotFoundAnyModelsWarning):22 self.pmv.get_subclasses_from_base(str)23 def test_validation_inspect_models(self):24 _valid = self.pmv.validation_inspect_models([str])25 self.assertTrue(_valid)26 self.assertFalse(_valid[1][0].valid)27 self.assertIn("has no attr", _valid[1][0].message)28 _valid = self.pmv.validation_inspect_models([Model])29 self.assertTrue(_valid)30 self.assertFalse(_valid[1][0].valid)31 self.assertIn("Unable to initialize model", _valid[1][0].message)32 def test_get_cmap_list(self):33 _cmap = self.pmv.get_cmap_list([], cmap_options=())34 self.assertEqual(_cmap, [])35 _cmap = self.pmv.get_cmap_list(36 [1] * 50, cmap_options=(), fallback_color=self.pmv.fallback_color37 )38 self.assertEqual(_cmap, [self.pmv.fallback_color] * 50)39 _cmap = self.pmv.get_cmap_list([1] * 5)40 self.assertEqual(len(_cmap), 5)41 def test___getattr__(self):42 with self.assertRaises(AttributeError):43 self.pmv.fake_attr44 def test___iter__(self):45 _iter = [i for i in self.pmv]46 self.assertIsInstance(_iter, list)47 def test_if_lmfit_models(self):48 if self.pmv.lmfit_models:49 _getdict = self.pmv.get_dict()50 self.assertIsInstance(_getdict, dict)51 _getdict = self.pmv.get_model_dict(self.pmv.lmfit_models)52 self.assertIsInstance(_getdict, dict)53def _debugging():54 self = TestPeakModelValidator()55 peaks = PeakModelValidator()56 self.pmv = peaks57 # all([isinstance(i.peak_model, Model) for i in peaks.lmfit_models])58 # all([isinstance(i.peak_model, Model) for i in peaks.get_dict().values()])59if __name__ == "__main__":...
Check out the latest blogs from LambdaTest on this topic:
I was once asked at a testing summit, “How do you manage a QA team using scrum?” After some consideration, I realized it would make a good article, so here I am. Understand that the idea behind developing software in a scrum environment is for development teams to self-organize.
The web paradigm has changed considerably over the last few years. Web 2.0, a term coined way back in 1999, was one of the pivotal moments in the history of the Internet. UGC (User Generated Content), ease of use, and interoperability for the end-users were the key pillars of Web 2.0. Consumers who were only consuming content up till now started creating different forms of content (e.g., text, audio, video, etc.).
Mobile devices and mobile applications – both are booming in the world today. The idea of having the power of a computer in your pocket is revolutionary. As per Statista, mobile accounts for more than half of the web traffic worldwide. Mobile devices (excluding tablets) contributed to 54.4 percent of global website traffic in the fourth quarter of 2021, increasing consistently over the past couple of years.
Even though several frameworks are available in the market for automation testing, Selenium is one of the most renowned open-source frameworks used by experts due to its numerous features and benefits.
JUnit is one of the most popular unit testing frameworks in the Java ecosystem. The JUnit 5 version (also known as Jupiter) contains many exciting innovations, including support for new features in Java 8 and above. However, many developers still prefer to use the JUnit 4 framework since certain features like parallel execution with JUnit 5 are still in the experimental phase.
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!!