Best Python code snippet using hypothesis
test_ident_hash.py
Source:test_ident_hash.py
...17 if sys.version_info >= (3,) and os.path.exists('/usr/bin/python3'):18 out = subprocess.check_output(['/usr/bin/python3', '--version'])19 return out < b'Python 3.4'20class SplitIdentTestCase(unittest.TestCase):21 def call_target(self, *args, **kwargs):22 from cnxtransforms.ident_hash import split_ident_hash23 return split_ident_hash(*args, **kwargs)24 def test_empty_value(self):25 # Case of supplying the utility function with an empty indent-hash.26 ident_hash = ''27 with self.assertRaises(IdentHashSyntaxError):28 self.call_target(ident_hash)29 def test_complete_data(self):30 # Simple case of supplying the correct information and checking31 # for the correct results.32 expected_id, expected_version = (33 '85e57f79-02b3-47d2-8eed-c1bbb1e1d5c2', '1.12',34 )35 ident_hash = "{}@{}".format(expected_id, expected_version)36 id, version = self.call_target(ident_hash)37 self.assertEqual(id, expected_id)38 self.assertEqual(version, expected_version)39 def test_uuid_only_w_at_sign(self):40 expected_id = '85e57f79-02b3-47d2-8eed-c1bbb1e1d5c2'41 ident_hash = "{}@".format(expected_id)42 with self.assertRaises(IdentHashSyntaxError):43 self.call_target(ident_hash)44 def test_uuid_only(self):45 # Case where the UUID has been the only value supplied in the46 # ident-hash.47 # This is mostly testing that the version value returns None.48 expected_id = '85e57f79-02b3-47d2-8eed-c1bbb1e1d5c2'49 ident_hash = expected_id50 with self.assertRaises(IdentHashMissingVersion) as cm:51 self.call_target(ident_hash)52 exc = cm.exception53 self.assertEqual(exc.id, expected_id)54 def test_invalid_id(self):55 # Case for testing for an invalid identifier.56 ident_hash = "not-a-valid-id@"57 from cnxtransforms.ident_hash import IdentHashSyntaxError58 with self.assertRaises(IdentHashSyntaxError):59 self.call_target(ident_hash)60 def test_invalid_syntax(self):61 # Case for testing the ident-hash's syntax guards.62 ident_hash = "85e57f7902b347d28eedc1bbb1e1d5c2@1.2@select*frommodules"63 from cnxtransforms.ident_hash import IdentHashSyntaxError64 with self.assertRaises(IdentHashSyntaxError):65 self.call_target(ident_hash)66 def test_w_split_version(self):67 expected_id, expected_version = (68 '85e57f79-02b3-47d2-8eed-c1bbb1e1d5c2',69 ('1', '12', ),70 )71 ident_hash = "{}@{}".format(expected_id, '.'.join(expected_version))72 id, version = self.call_target(ident_hash, split_version=True)73 self.assertEqual(id, expected_id)74 self.assertEqual(version, expected_version)75 def test_w_split_version_on_major_version(self):76 expected_id, expected_version = (77 '85e57f79-02b3-47d2-8eed-c1bbb1e1d5c2',78 ('1', None, ),79 )80 ident_hash = "{}@{}".format(expected_id, expected_version[0])81 id, version = self.call_target(ident_hash, split_version=True)82 self.assertEqual(id, expected_id)83 self.assertEqual(version, expected_version)84 def test_w_split_version_no_version(self):85 expected_id = '85e57f79-02b3-47d2-8eed-c1bbb1e1d5c2'86 ident_hash = expected_id87 with self.assertRaises(IdentHashMissingVersion) as cm:88 self.call_target(ident_hash, True)89 exc = cm.exception90 self.assertEqual(exc.id, expected_id)91 def test_short_id_wo_version(self):92 ident_hash = 'abcdefgh'93 with self.assertRaises(IdentHashShortId) as cm:94 self.call_target(ident_hash)95 exc = cm.exception96 self.assertEqual(exc.id, 'abcdefgh')97 self.assertEqual(exc.version, '')98 def test_short_id_w_version(self):99 ident_hash = 'abcdefgh@10'100 with self.assertRaises(IdentHashShortId) as cm:101 self.call_target(ident_hash)102 exc = cm.exception103 self.assertEqual(exc.id, 'abcdefgh')104 self.assertEqual(exc.version, '10')105class JoinIdentTestCase(unittest.TestCase):106 def call_target(self, *args, **kwargs):107 from cnxtransforms.ident_hash import join_ident_hash108 return join_ident_hash(*args, **kwargs)109 def test(self):110 id = '85e57f79-02b3-47d2-8eed-c1bbb1e1d5c2'111 version = ('2', '4', )112 expected = "{}@{}".format(id, '.'.join(version))113 ident_hash = self.call_target(id, version)114 self.assertEqual(expected, ident_hash)115 def test_w_UUID(self):116 id = uuid.uuid4()117 version = None118 expected = str(id)119 ident_hash = self.call_target(id, version)120 self.assertEqual(expected, ident_hash)121 def test_w_null_version(self):122 id = '85e57f79-02b3-47d2-8eed-c1bbb1e1d5c2'123 version = None124 expected = id125 ident_hash = self.call_target(id, version)126 self.assertEqual(expected, ident_hash)127 def test_w_null_str_version(self):128 id = '85e57f79-02b3-47d2-8eed-c1bbb1e1d5c2'129 version = ''130 expected = id131 ident_hash = self.call_target(id, version)132 self.assertEqual(expected, ident_hash)133 def test_w_str_version(self):134 id = '85e57f79-02b3-47d2-8eed-c1bbb1e1d5c2'135 version = '2'136 expected = "{}@{}".format(id, version)137 ident_hash = self.call_target(id, version)138 self.assertEqual(expected, ident_hash)139 def test_w_major_version(self):140 id = '85e57f79-02b3-47d2-8eed-c1bbb1e1d5c2'141 version = ('2', None, )142 expected = "{}@{}".format(id, version[0])143 ident_hash = self.call_target(id, version)144 self.assertEqual(expected, ident_hash)145 def test_w_double_null_version(self):146 id = '85e57f79-02b3-47d2-8eed-c1bbb1e1d5c2'147 version = (None, None, )148 expected = id149 ident_hash = self.call_target(id, version)150 self.assertEqual(expected, ident_hash)151 def test_w_invalid_version_sequence(self):152 id = '85e57f79-02b3-47d2-8eed-c1bbb1e1d5c2'153 version = ('1', )154 with self.assertRaises(AssertionError):155 self.call_target(id, version)156 def test_w_integer_version(self):157 id = '85e57f79-02b3-47d2-8eed-c1bbb1e1d5c2'158 version = (1, 2, )159 expected = '{}@1.2'.format(id)160 ident_hash = self.call_target(id, version)161 self.assertEqual(expected, ident_hash)162def identifiers_equal(identifier1, identifier2):163 fulluuid1 = None164 fulluuid2 = None165 base64hash1 = None166 base64hash2 = None167 shortid1 = None168 shortid2 = None169 try:170 type1 = CNXHash.validate(identifier1)171 type2 = CNXHash.validate(identifier2)172 except IdentHashSyntaxError:173 return False174 if type1 == CNXHash.FULLUUID and type2 == CNXHash.FULLUUID:...
JmpAbsMacro.py
Source:JmpAbsMacro.py
1from writers.CWriter import CWriter2class JmpAbsMacro(object):3 def __init__(self, args, label):4 self.args = args5 assert len(self.args) == 16 7 call_target = self.args[0]8 call_target = call_target.strip()9 assert call_target.startswith('{')10 assert call_target.endswith('}')11 self.call_target = call_target[1:-1]12 self.label = label13 def expand(self):14 """Expands the macro into what should be passed to the GNU assembler""" 15 return '\n'.join(['nop'] * 5)16 def generate(self, writer, target, obj):17 """Returns the assembly generation code, i.e. the C code that generates the assembly at run time"""18 if type(writer) != CWriter and type(getattr(writer, 'inner', None)) != CWriter:19 raise Exception('CallAbsMacro currently only supports C as target language')20 # TODO: This is as ugly as it is because the DSL is applied *after*21 # C macros are expanded, which means that we cannot use them in DSL 22 # macros.23 writer.write_raw("""24 *((%(target)s)++)=0xe9;\n\n25 if ((((ulong_t)(%(call_target)s) - (ulong_t)(%(target)s) - 4) & (uint32_t)0x0) != 0) {\n\n26 fllwrite(1, "Relative jump target is too far away!\\n");\n27 __asm__ volatile("hlt" : : : "memory");\n28 }\n\n29 *((uint32_t*)(%(target)s)) = (uint32_t)((ulong_t)(%(call_target)s) - (ulong_t)(%(target)s) - 4);\n\n30 (%(target)s)+=4;\n\n31 """ % {'target': target, 'call_target': self.call_target})...
CallAbsMacro.py
Source:CallAbsMacro.py
1from writers.CWriter import CWriter2class CallAbsMacro(object):3 def __init__(self, args, label):4 self.args = args5 assert len(self.args) == 16 7 call_target = self.args[0]8 call_target = call_target.strip()9 assert call_target.startswith('{')10 assert call_target.endswith('}')11 self.call_target = call_target[1:-1]12 self.label = label13 def expand(self):14 """Expands the macro into what should be passed to the GNU assembler"""15 return '\n'.join(['nop'] * 5)16 def generate(self, writer, target, obj):17 """Returns the assembly generation code, i.e. the C code that generates the assembly at run time"""18 if type(writer) != CWriter and type(getattr(writer, 'inner', None)) != CWriter:19 raise Exception('CallAbsMacro currently only supports C as target language')20 # TODO: This is as ugly as it is because the DSL is applied *after*21 # C macros are expanded, which means that we cannot use them in DSL 22 # macros.23 writer.write_raw("""24 *((%(target)s)++)=0xe8;\n\n25 if ((((ulong_t)(%(call_target)s) - (ulong_t)(%(target)s) - 4) & (uint32_t)0x0) != 0) {\n\n26 fllwrite(1, "Relative jump target is too far away!\\n");\n27 __asm__ volatile("hlt" : : : "memory");\n28 }\n\n29 *((uint32_t*)(%(target)s)) = (uint32_t)((ulong_t)(%(call_target)s) - (ulong_t)(%(target)s) - 4);\n\n30 (%(target)s)+=4;\n\n31 """ % {'target': target, 'call_target': self.call_target})...
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!!