How to use method_tests method in Slash

Best Python code snippet using slash

test_collections.py

Source:test_collections.py Github

copy

Full Screen

1import unittest2import random3from ..collections import TypedList, TypedDict, DictSet, OrderedSet, SplitList4from ...Meta.bencode import bencode, bdecode5from ...Meta.Info import MetaInfo6class APITest(object):7 """API test mixin - Requires that all attributes of `baseclass` be8 present in `thisclass`"""9 baseclass = None10 thisclass = None11 initargs = ()12 initkwargs = {}13 def test_apisuperset(self):14 for attr in dir(self.baseclass):15 self.assertTrue(hasattr(self.thisclass, attr))16 def setUp(self):17 self.base = self.baseclass(*self.initargs, **self.initkwargs)18 self.this = self.thisclass(*self.initargs, **self.initkwargs)19class ComparableAPITest(APITest):20 """Comparable API test mixin - Requires that `thisclass` objects be21 testable for equality with `baseclass` objects, and that the methods and22 functions in `method_tests` and `function_tests` have the same effect23 on and produce the same output from both objects.24 `method_tests` is a list of (method_name, args, kwargs) that are25 run sequentially.26 `function_tests` is a list of (function, args, kwargs) that are run27 sequentially.28 """29 method_tests = []30 function_tests = []31 def setUp(self):32 super().setUp()33 self.assertEqual(self.base, self.this)34 def test_methods(self):35 for attr, args, kwargs in self.method_tests:36 with self.subTest(attr=attr):37 x = getattr(self.base, attr)(*args, **kwargs)38 y = getattr(self.this, attr)(*args, **kwargs)39 self.assertEqual(self.base, self.this)40 self.assertEqual(x, y)41 def test_functions(self):42 for func, args, kwargs in self.function_tests:43 with self.subTest(func=func.__name__):44 x = func(self.base, *args, **kwargs)45 y = func(self.this, *args, **kwargs)46 self.assertEqual(self.base, self.this)47 self.assertEqual(x, y)48class CopyAPITest(ComparableAPITest):49 """Mixin to test object copying and modifying methods on copies of objects50 Mostly useful when undoing is non-trivial51 """52 copy_tests = []53 def test_copy(self):54 bcopy = self.base.copy()55 tcopy = self.this.copy()56 self.assertEqual(bcopy, tcopy)57 self.assertIsNot(tcopy, self.this)58 self.assertEqual(type(tcopy), type(self.this))59 def test_copymethods(self):60 for attr, args, kwargs in self.copy_tests:61 with self.subTest(attr=attr):62 bcopy = self.base.copy()63 tcopy = self.this.copy()64 x = getattr(bcopy, attr)(*args, **kwargs)65 y = getattr(tcopy, attr)(*args, **kwargs)66 self.assertEqual(bcopy, tcopy)67 self.assertEqual(x, y)68class TypedListAPITest(CopyAPITest, unittest.TestCase):69 baseclass = list70 thisclass = TypedList71 init_args = "abcdef"72 method_tests = [('append', ('g',), {}),73 ('pop', (-1,), {}),74 ('insert', (1, 'q'), {}),75 ]76class TypedDictAPITest(CopyAPITest, unittest.TestCase):77 baseclass = dict78 thisclass = TypedDict79class DictSetTest(CopyAPITest, unittest.TestCase):80 baseclass = set81 thisclass = DictSet82 initargs = ("abcdef",)83 comparator = set("defghi")84 subset = set("abc")85 superset = set("abcdefg")86 method_tests = [('add', ('g',), {}),87 ('discard', ('g',), {}),88 ('difference', (comparator,), {}),89 ('intersection', (comparator,), {}),90 ('symmetric_difference', (comparator,), {}),91 ('issubset', (comparator,), {}),92 ('issubset', (subset,), {}),93 ('issubset', (superset,), {}),94 ('issuperset', (comparator,), {}),95 ('issuperset', (subset,), {}),96 ('issuperset', (superset,), {}),97 ('union', (comparator,), {}),98 ]99 copy_tests = [('difference_update', (comparator,), {}),100 ('symmetric_difference_update', (comparator,), {}),101 ('intersection_update', (comparator,), {}),102 ('update', (comparator,), {}),103 ]104 def test_bencoding(self):105 orig = DictSet(('a', 'b', 'c'))106 self.assertEqual(bencode(orig), b'd1:ai1e1:bi1e1:ci1ee')107 self.assertEqual(DictSet(bdecode(bencode(orig))), orig)108 def test_comparisons(self):109 # Equality should imply the following:110 self.assertTrue(self.this <= self.base)111 self.assertTrue(self.this >= self.base)112 self.assertTrue(self.base <= self.this)113 self.assertTrue(self.base >= self.this)114 tcopy = self.this.copy()115 x = tcopy.pop()116 self.assertTrue(x not in tcopy) # value removed117 self.assertTrue(x in self.this) # original unaffected118 # Test comparisons in DictSet119 self.assertEqual(len(tcopy), len(self.base) - 1)120 self.assertTrue(tcopy < self.this)121 self.assertTrue(tcopy <= self.this)122 self.assertTrue(self.this >= tcopy)123 self.assertTrue(self.this > tcopy)124 bcopy = self.base.copy()125 bcopy.pop()126 # Check that comparisons with normal sets work as expected127 self.assertTrue(self.base > tcopy)128 self.assertTrue(self.base >= tcopy)129 self.assertTrue(bcopy < self.this)130 self.assertTrue(bcopy <= self.this)131class SplitListTest(unittest.TestCase):132 def test_null(self):133 self.assertEqual(SplitList(), SplitList([]))134 self.assertEqual(SplitList(), SplitList(''))135 self.assertEqual(SplitList(), SplitList(['']))136 def test_announcelist(self):137 cls = MetaInfo.AnnounceList138 self.assertEqual(cls(), cls(''))139 self.assertEqual(cls(), cls([]))140 self.assertEqual(cls('a,b,c'), [['a', 'b', 'c']])141 self.assertEqual(cls('a|b|c'), [['a'], ['b'], ['c']])142 self.assertEqual(cls('a,b|c'), [['a', 'b'], ['c']])143class OrderedSetTest(unittest.TestCase):144 def test_orderedpop(self):145 """Test that removing arbitrary values from an ordered set is146 the same as removing from a sorted list"""147 for _ in range(10):148 vals = random.sample(range(100), 10)149 oset = OrderedSet(vals)150 sorted_vals = sorted(vals)151 while len(oset) > 0:152 n = random.randrange(len(oset))153 oset.pop(n)154 sorted_vals.pop(n)...

Full Screen

Full Screen

__init__.py

Source:__init__.py Github

copy

Full Screen

1# -*- coding: utf-8 -*-2"""Files to test MerLink.3There are 8 components of Merlink functionality:40. CLI (+integration tests)51. GUI (+integration tests)62. Client VPN additions to Soup Browser73. Dashboard VPN additions to Soup Browser84. Test page routes95. VPN connection106. Utils scattered around the program117. Mechanical Turk: Things that must be tested manually for the time being.12"""13import unittest14from test.method_tests.test_client_vpn_browser import TestClientVpnBrowser15from test.method_tests.test_dashboard_browser import TestLogins16from test.method_tests.test_merlink_cli import TestMerlinkCli17from test.method_tests.test_merlink_gui import TestMerlinkWindow18from test.method_tests.test_page_routes import TestPageRoutes19from test.method_tests.test_vpn_connection import TestVpnConnection20"""21fast = unittest.TestSuite()22fast.addTests([23 TestClientVpnBrowser,24 TestMerlinkCli,25 TestMerlinkWindow,26 TestPageRoutes,27 TestVpnConnection28])29slow = unittest.TestSuite()30slow.addTests(TestLogins)31alltests = unittest.TestSuite([fast, slow])...

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