How to use assert_dict_subset method in Testify

Best Python code snippet using Testify_python

test.py

Source:test.py Github

copy

Full Screen

...53 assert str(expect_typedef('Typedef1s')) == 'struct S'54 assert str(expect_typedef('Typedef2s')) == 'Typedef1s'55 assert str(expect_typedef('Typedef3s')) == 'Typedef2s'5657def assert_dict_subset(actual, expected):58 for k in expected:59 try:60 assert actual[k] == expected[k]61 except:62 raise ValueError(repr((actual, expected)))6364def test_structure_padding():65 from . import _structure_fields, GAP_MEMBER_NAME, PADDING_MEMBER_NAME, END_MEMBER_NAME6667 def run_on_struct(size, data):68 bv = bn.BinaryView()69 structure = bn.Structure()70 structure.width = size71 for i, (offset, typestr) in enumerate(data):72 structure.insert(offset, bv.parse_type_string(typestr)[0], f'field_{i}')73 structure.alignment = max(member.type.alignment for member in structure.members) # why do i have to do this manually74 return list(_structure_fields(structure))7576 # gap that is padding77 members = run_on_struct(0x08, [(0x00, 'int16_t'), (0x04, 'int32_t')])78 assert_dict_subset(members[1], {'offset': 0x02, 'name': PADDING_MEMBER_NAME})79 assert_dict_subset(members[2], {'offset': 0x04, 'name': 'field_1'})8081 # gap that isn't padding because of alignment that follows82 members = run_on_struct(0x0c, [(0x00, 'int16_t'), (0x04, 'int16_t'), (0x08, 'int32_t')])83 assert_dict_subset(members[1], {'offset': 0x02, 'name': GAP_MEMBER_NAME})8485 # gap that isn't padding because it's too large86 members = run_on_struct(0x0c, [(0x00, 'int16_t'), (0x08, 'int32_t')])87 assert_dict_subset(members[1], {'offset': 0x02, 'name': GAP_MEMBER_NAME})88 assert_dict_subset(members[2], {'offset': 0x08, 'name': 'field_1'})8990 # end padding91 members = run_on_struct(0x08, [(0x00, 'int32_t'), (0x04, 'int16_t')])92 assert_dict_subset(members[2], {'offset': 0x06, 'name': PADDING_MEMBER_NAME})93 assert_dict_subset(members[3], {'offset': 0x08, 'name': END_MEMBER_NAME})9495 # no end padding96 members = run_on_struct(0x06, [(0x00, 'int16_t'), (0x04, 'int16_t')])97 assert_dict_subset(members[2], {'offset': 0x04, 'name': 'field_1'})98 assert_dict_subset(members[3], {'offset': 0x06, 'name': END_MEMBER_NAME})99100def test_packed_struct():101 from . import _structure_fields, GAP_MEMBER_NAME, END_MEMBER_NAME102103 def run_on_struct(size, data):104 bv = bn.BinaryView()105 structure = bn.Structure()106 structure.packed = True107 structure.width = size108 for i, (offset, typestr) in enumerate(data):109 structure.insert(offset, bv.parse_type_string(typestr)[0], f'field_{i}')110 return list(_structure_fields(structure))111112 members = run_on_struct(0x0a, [(0x00, 'int16_t'), (0x04, 'int32_t'), (0x08, 'int16_t')])113 assert_dict_subset(members[0], {'offset': 0x00, 'name': 'field_0'})114 assert_dict_subset(members[1], {'offset': 0x02, 'name': GAP_MEMBER_NAME})115 assert_dict_subset(members[2], {'offset': 0x04, 'name': 'field_1'})116 assert_dict_subset(members[3], {'offset': 0x08, 'name': 'field_2'})117 assert_dict_subset(members[4], {'offset': 0x0a, 'name': END_MEMBER_NAME})118119 # end gap120 members = run_on_struct(0x0a, [(0x00, 'int16_t')])121 assert_dict_subset(members[0], {'offset': 0x00, 'name': 'field_0'})122 assert_dict_subset(members[1], {'offset': 0x02, 'name': GAP_MEMBER_NAME})123 assert_dict_subset(members[2], {'offset': 0x0a, 'name': END_MEMBER_NAME})124125def test_union():126 from . import _structure_fields127128 bv = bv_from_c_defs('''129 union Union {130 int32_t four;131 int16_t two;132 }133 ''')134 members = list(_structure_fields(bv.types['Union'].structure))135 assert len(members) == 2136 assert_dict_subset(members[0], {'offset': 0x00, 'name': 'four'}) ...

Full Screen

Full Screen

test_middleware.py

Source:test_middleware.py Github

copy

Full Screen

...73 expected_context_subset = {74 'course_id': 'test_org/test_course/test_run',75 'org_id': 'test_org',76 }77 self.assert_dict_subset(captured_context, expected_context_subset)78 def assert_dict_subset(self, superset, subset):79 """Assert that the superset dict contains all of the key-value pairs found in the subset dict."""80 for key, expected_value in subset.iteritems():81 self.assertEquals(superset[key], expected_value)82 def test_request_with_user(self):83 user_id = 184 username = sentinel.username85 request = self.request_factory.get('/courses/')86 request.user = User(pk=user_id, username=username)87 context = self.get_context_for_request(request)88 self.assert_dict_subset(context, {89 'user_id': user_id,90 'username': username,91 })92 def test_request_with_session(self):93 request = self.request_factory.get('/courses/')94 SessionMiddleware().process_request(request)95 request.session.save()96 session_key = request.session.session_key97 expected_session_key = self.track_middleware.encrypt_session_key(session_key)98 self.assertEquals(len(session_key), len(expected_session_key))99 context = self.get_context_for_request(request)100 self.assert_dict_subset(context, {101 'session': expected_session_key,102 })103 @override_settings(SECRET_KEY='85920908f28904ed733fe576320db18cabd7b6cd')104 def test_session_key_encryption(self):105 session_key = '665924b49a93e22b46ee9365abf28c2a'106 expected_session_key = '3b81f559d14130180065d635a4f35dd2'107 encrypted_session_key = self.track_middleware.encrypt_session_key(session_key)108 self.assertEquals(encrypted_session_key, expected_session_key)109 def test_request_headers(self):110 ip_address = '10.0.0.0'111 user_agent = 'UnitTest/1.0'112 factory = RequestFactory(REMOTE_ADDR=ip_address, HTTP_USER_AGENT=user_agent)113 request = factory.get('/some-path')114 context = self.get_context_for_request(request)115 self.assert_dict_subset(context, {116 'ip': ip_address,117 'agent': user_agent,...

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