How to use assert_true method in wpt

Best JavaScript code snippet using wpt

test_datasource_module.py

Source:test_datasource_module.py Github

copy

Full Screen

...123 pass124 @log_function(logger)125 def test_01_get_permission(self):126 permission_list = self.module.get_all_permissions()127 assert_true(type(permission_list) is list)128 for p in permission_list:129 assert_true(type(p) is Permission)130 assert_true(len(permission_list) == 3)131 assert_equal(permission_list[0].name, 'p1')132 assert_equal(permission_list[0].description, 'init_pppp1')133 assert_equal(permission_list[1].name, 'p2')134 assert_equal(permission_list[1].description, 'init_pppp2')135 assert_equal(permission_list[2].name, 'p3')136 assert_equal(permission_list[2].description, 'init_pppp3')137 @log_function(logger)138 def test_02_get_role(self):139 roles_list = self.module.get_all_roles()140 assert_true(type(roles_list) is list)141 for r in roles_list:142 assert_true(type(r) is Role)143 assert_true(type(r.permissions) is list)144 for p in r.permissions:145 assert_true(type(p) is Permission)146 role_2 = self.module.get_role(2)147 assert_true(type(role_2) is Role)148 assert_true(type(role_2.permissions) is list)149 for p in role_2.permissions:150 assert_true(type(p) is Permission)151 role_found = None152 for r in roles_list:153 if r.id == 2:154 role_found = r155 break156 assert_true(len(roles_list) == 2)157 assert_true(role_found is not None)158 assert_equal(role_found.id, 2)159 assert_equal(role_found.id, role_2.id)160 assert_equal(role_found.name, role_2.name)161 assert_equal(role_found.description, role_2.description)162 assert_equal(len(role_found.permissions), len(role_2.permissions))163 long = len(role_found.permissions)164 for index in range(long):165 assert_equal(role_found.permissions[index].id, role_2.permissions[index].id)166 assert_equal(role_found.permissions[index].name, role_2.permissions[index].name)167 assert_equal(role_found.permissions[index].description, role_2.permissions[index].description)168 @log_function(logger)169 def test_03_get_user(self):170 users_list = self.module.get_all_users()171 assert_true(type(users_list) is list)172 for u in users_list:173 assert_true(type(u) is User)174 assert_true(type(u.roles) is list)175 for r in u.roles:176 assert_true(type(r) is Role)177 assert_true(type(u.roles) is list)178 for p in r.permissions:179 assert_true(type(p) is Permission)180 user_1 = self.module.get_user(1)181 assert_true(type(user_1) is User)182 assert_true(type(user_1.roles) is list)183 for r in user_1.roles:184 assert_true(type(r) is Role)185 assert_true(type(r.permissions) is list)186 for p in r.permissions:187 assert_true(type(p) is Permission)188 user_found = None189 for u in users_list:190 if u.id == 1:191 user_found = u192 break193 assert_true(len(users_list) == 2)194 assert_true(user_found is not None)195 assert_equal(user_found.id, user_1.id)196 assert_equal(user_found.username, user_1.username)197 assert_equal(user_found.password, user_1.password)198 assert_equal(user_found.first_name, user_1.first_name)199 assert_equal(user_found.family_name, user_1.family_name)200 assert_equal(user_found.email, user_1.email)201 assert_equal(len(user_found.roles), len(user_1.roles))202 long = len(user_found.roles)203 for index in range(long):204 assert_equal(user_found.roles[index].id, user_1.roles[index].id)205 assert_equal(user_found.roles[index].name, user_1.roles[index].name)206 assert_equal(user_found.roles[index].description, user_1.roles[index].description)207 @log_function(logger)208 def test_04_get_case_type(self):209 case_types_list = self.module.get_all_case_types()210 assert_true(type(case_types_list) is list)211 for ct in case_types_list:212 assert_true(type(ct) is CaseType)213 type_3 = self.module.get_case_type(3)214 assert_true(type(type_3) is CaseType)215 type_found = None216 for t in case_types_list:217 if t.id == 3:218 type_found = t219 break220 assert_true(len(case_types_list) == 3)221 assert_true(type_found is not None)222 assert_equal(type_found.id, type_3.id)223 assert_equal(type_found.name, type_3.name)224 assert_equal(type_found.description, type_3.description)225 @log_function(logger)226 def test_05_get_case_status(self):227 case_status_list = self.module.get_all_case_status()228 assert_true(type(case_status_list) is list)229 for cs in case_status_list:230 assert_true(type(cs) is CaseStatus)231 status_2 = self.module.get_case_status(2)232 assert_true(type(status_2) is CaseStatus)233 status_found = None234 for s in case_status_list:235 if s.id == 2:236 status_found = s237 break238 assert_true(status_found is not None)239 assert_true(len(case_status_list) == 3)240 assert_equal(status_found.id, status_2.id)241 assert_equal(status_found.name, status_2.name)242 assert_equal(status_found.description, status_2.description)243 @log_function(logger)244 def test_06_get_case(self):245 case_list = self.module.get_all_cases()246 assert_true(type(case_list) is list)247 for c in case_list:248 assert_true(type(c) is Case)249 assert_true(type(c.case_type) is CaseType)250 assert_true(type(c.case_status) is CaseStatus)251 case_2 = self.module.get_case(2)252 assert_true(type(case_2) is Case)253 assert_true(type(case_2.case_type) is CaseType)254 assert_true(type(case_2.case_status) is CaseStatus)255 case_found = None256 for c in case_list:257 if c.id == 2:258 case_found = c259 break260 assert_true(len(case_list) == 2)261 assert_equal(case_found.id, case_2.id)262 assert_equal(case_found.formal_name, case_2.formal_name)263 assert_equal(case_found.friend_name, case_2.friend_name)264 assert_equal(case_found.creation_datetime, case_2.creation_datetime)265 assert_equal(case_found.num_win, case_2.num_win)266 assert_equal(case_found.num_lin, case_2.num_lin)267 assert_equal(case_found.num_ios, case_2.num_ios)268 assert_equal(case_found.num_mal, case_2.num_mal)269 assert_equal(case_found.num_pac, case_2.num_pac)270 assert_equal(case_found.num_log, case_2.num_log)271 assert_equal(case_found.case_type.id, case_2.case_type.id)272 assert_equal(case_found.case_type.name, case_2.case_type.name)273 assert_equal(case_found.case_type.description, case_2.case_type.description)274 assert_equal(case_found.case_status.id, case_2.case_status.id)275 assert_equal(case_found.case_status.name, case_2.case_status.name)276 assert_equal(case_found.case_status.description, case_2.case_status.description)277 @log_function(logger)278 def test_07_get_evidence(self):279 evidence_list = self.module.get_all_evidences()280 assert_true(type(evidence_list) is list)281 for e in evidence_list:282 assert_true(type(e) is Evidence)283 assert_true(type(e.owner) is User)284 evidence_1 = self.module.get_evidence(1)285 assert_true(type(evidence_1) is Evidence)286 assert_true(type(evidence_1.owner) is User)287 evidence_found = None288 for e in evidence_list:289 if e.id == 1:290 evidence_found = e291 break292 assert_true(len(evidence_list) == 2)293 assert_true(evidence_found is not None)294 assert_equal(evidence_found.id, evidence_1.id)295 assert_equal(evidence_found.alias, evidence_1.alias)296 assert_equal(evidence_found.size, evidence_1.size)297 assert_equal(evidence_found.owner.id, evidence_1.owner.id)298 assert_equal(evidence_found.owner.username, evidence_1.owner.username)299 assert_equal(evidence_found.owner.password, evidence_1.owner.password)300 assert_equal(evidence_found.owner.first_name, evidence_1.owner.first_name)301 assert_equal(evidence_found.owner.family_name, evidence_1.owner.family_name)302 assert_equal(evidence_found.owner.email, evidence_1.owner.email)303 @log_function(logger)304 def test_08_get_upload(self):305 upload_list = self.module.get_all_uploads(2)306 assert_true(type(upload_list) is list)307 for u in upload_list:308 assert_true(type(u) is Upload)309 assert_true(type(u.evidence) is Evidence)310 upload_5 = self.module.get_upload(5)311 assert_true(type(upload_5) is Upload)312 assert_true(type(upload_5.evidence) is Evidence)313 upload_found = None314 for u in upload_list:315 if u.id == 5:316 upload_found = u317 break318 assert_true(len(upload_list) == 4)319 assert_true(upload_found is not None)320 assert_equal(upload_found.id, upload_5.id)321 assert_equal(upload_found.path, upload_5.path)322 assert_equal(upload_found.size, upload_5.size)323 assert_equal(upload_found.type, upload_5.type)324 assert_equal(upload_found.evidence.id, upload_5.evidence.id)325 assert_equal(upload_found.evidence.alias, upload_5.evidence.alias)326 assert_equal(upload_found.evidence.size, upload_5.evidence.size)327 @log_function(logger)328 def test_09_get_file(self):329 file_list = self.module.get_all_files(2)330 assert_true(type(file_list) is list)331 for f in file_list:332 assert_true(type(f) is File)333 assert_true(type(f.upload) is Upload)334 file_4 = self.module.get_file(4)335 assert_true(type(file_4) is File)336 assert_true(type(file_4.upload) is Upload)337 file_found = None338 for f in file_list:339 if f.id == 4:340 file_found = f341 break342 assert_true(len(file_list) == 3)343 assert_true(file_found is not None)344 assert_equal(file_found.id, file_4.id)345 assert_equal(file_found.path, file_4.path)346 assert_equal(file_found.size, file_4.size)347 assert_equal(file_found.name, file_4.name)348 assert_equal(file_found.hash_md5, file_4.hash_md5)349 assert_equal(file_found.hash_sha256, file_4.hash_sha256)350 assert_equal(file_found.upload.id, file_4.upload.id)351 assert_equal(file_found.upload.size, file_4.upload.size)352 assert_equal(file_found.upload.type, file_4.upload.type)353 @log_function(logger)354 def test_10_get_entity(self):355 entity_list = self.module.get_all_entities()356 assert_true(type(entity_list) is list)357 for e in entity_list:358 assert_true(type(e) is Entity)359 assert_true(len(entity_list) == 2)360 assert_equal(entity_list[0].name, 'ent name 1')361 assert_equal(entity_list[0].description, 'ent desc 1')362 assert_equal(entity_list[1].name, 'ent name 2')363 assert_equal(entity_list[1].description, 'ent desc 2')364 @log_function(logger)365 def test_11_get_instance(self):366 instance_list = self.module.get_all_instances(1)367 assert_true(type(instance_list) is list)368 for i in instance_list:369 assert_true(type(i) is Instance)370 assert_true(type(i.entity) is Entity)371 instance_2 = self.module.get_instance(2)372 assert_true(type(instance_2) is Instance)373 assert_true(type(instance_2.entity) is Entity)374 instance_found = None375 for i in instance_list:376 if i.id == 2:377 instance_found = i378 break379 assert_true(len(instance_list) == 3)380 assert_true(instance_found is not None)381 assert_equal(instance_found.id, instance_2.id)382 assert_equal(instance_found.name, instance_2.name)383 assert_equal(instance_found.entity.id, instance_2.entity.id)384 assert_equal(instance_found.entity.name, instance_2.entity.name)385 assert_equal(instance_found.entity.description, instance_2.entity.description)386 @log_function(logger)387 def test_12_get_property(self):388 property_list = self.module.get_all_properties(2)389 assert_true(type(property_list) is list)390 for p in property_list:391 assert_true(type(p) is Property)392 assert_true(type(p.entity) is Entity)393 property_6 = self.module.get_property(6)394 assert_true(type(property_6) is Property)395 assert_true(type(property_6.entity) is Entity)396 property_found = None397 for p in property_list:398 if p.id == 6:399 property_found = p400 break401 assert_true(len(property_list) == 4)402 assert_true(property_found is not None)403 assert_equal(property_found.id, property_6.id)404 assert_equal(property_found.name, property_6.name)405 assert_equal(property_found.description, property_6.description)406 assert_equal(property_found.entity.id, property_6.entity.id)407 assert_equal(property_found.entity.name, property_6.entity.name)408 assert_equal(property_found.entity.description, property_6.entity.description)409 @log_function(logger)410 def test_13_get_value(self):411 value_list = self.module.get_all_values(4)412 assert_true(type(value_list) is list)413 for v in value_list:414 assert_true(type(v) is Value)415 assert_true(type(v.property) is Property)416 assert_true(type(v.instance) is Instance)417 value_4 = self.module.get_value(4)418 assert_true(type(value_4) is Value)419 assert_true(type(value_4.property) is Property)420 assert_true(type(value_4.instance) is Instance)421 value_found = None422 for v in value_list:423 if v.id == 4:424 value_found = v425 assert_true(len(value_list) == 4)426 assert_true(value_found is not None)427 assert_equal(value_found.id, value_4.id)428 assert_equal(value_found.value, value_4.value)429 assert_equal(value_found.property.id, value_4.property.id)430 assert_equal(value_found.instance.id, value_4.instance.id)431 assert_equal(value_found.instance.entity.id, value_4.instance.entity.id)432 @log_function(logger)433 def test_14_set_permission(self):434 name = 'test name 1'435 description = 'test desc 1'436 new_permission = self.module.create_permission(name, description)437 new_id = new_permission[0].id438 permission_list = self.module.get_all_permissions()439 assert_true(type(permission_list) is list)440 for p in permission_list:441 assert_true(type(p) is Permission)442 permission_found = None443 for p in permission_list:444 if p.id == new_id:445 permission_found = p446 break447 assert_true(new_permission[1])448 assert_true(permission_found is not None)449 assert_true(type(new_permission[0]) is Permission)450 assert_equal(permission_found.id, new_id)451 assert_equal(permission_found.name, name)452 assert_equal(permission_found.description, description)453 @log_function(logger)454 def test_15_set_role(self):455 perm_1_name = 'perm 1 name'456 perm_1_description = 'perm 1 desc'457 perm_2_name = 'perm 2 name'458 perm_2_description = 'perm 2 desc'459 role_name = 'role name'460 role_description = 'role description'461 perm_names = list()462 perm_names.append(perm_1_name)463 perm_names.append(perm_2_name)464 perm_desc = list()465 perm_desc.append(perm_1_description)466 perm_desc.append(perm_2_description)467 new_permission_1 = self.module.create_permission(perm_1_name, perm_1_description)468 assert_true(new_permission_1[0] is not None)469 assert_true(new_permission_1[1])470 assert_true(type(new_permission_1[0]) is Permission)471 new_permission_2 = self.module.create_permission(perm_2_name, perm_2_description)472 assert_true(new_permission_2[0] is not None)473 assert_true(new_permission_2[1])474 assert_true(type(new_permission_2[0]) is Permission)475 permission_list = list()476 permission_list.append(new_permission_1[0])477 permission_list.append(new_permission_2[0])478 new_role = self.module.create_role(role_name, role_description, permission_list)479 assert_true(new_role[0] is not None)480 assert_true(new_role[1])481 assert_true(type(new_role[0]) is Role)482 for p in new_role[0].permissions:483 assert_true(type(p) is Permission)484 new_role_id = new_role[0].id485 role_found = self.module.get_role(new_role_id)486 assert_true(role_found is not None)487 assert_equal(role_found.id, new_role_id)488 assert_true(type(role_found) is Role)489 assert_true(type(role_found.permissions) is list)490 for p in role_found.permissions:491 assert_true(type(p) is Permission)492 assert_equal(role_found.name, role_name)493 assert_equal(role_found.description, role_description)494 assert_equal(len(role_found.permissions), len(permission_list))495 long_lista = len(role_found.permissions)496 for index in range(long_lista):497 assert_equal(role_found.permissions[index].id, permission_list[index].id)498 assert_equal(role_found.permissions[index].name, perm_names[index])499 assert_equal(role_found.permissions[index].description, perm_desc[index])500 @log_function(logger)501 def test_16_set_user(self):502 username = 'test user username 1'503 password = 'test user password 1'504 first_name = 'test user first 1'505 family_name = 'test user family 1'506 email = 'test user email 1'507 permission_list = self.module.get_all_permissions()508 assert_true(type(permission_list) is list)509 for p in permission_list:510 assert_true(type(p) is Permission)511 perm_1 = permission_list[0]512 perm_2 = permission_list[1]513 perm_3 = permission_list[2]514 pl1 = list()515 pl1.append(perm_1)516 pl1.append(perm_3)517 pl2 = list()518 pl2.append(perm_1)519 pl2.append(perm_2)520 pl2.append(perm_3)521 role_1_name = 'role 1 name'522 role_1_description = 'role 1 description'523 role_2_name = 'role 2 name'524 role_2_description = 'role 2 description'525 role_1_tuple = self.module.create_role(role_1_name, role_1_description, pl1)526 assert_true(role_1_tuple[0] is not None)527 assert_true(role_1_tuple[1])528 assert_true(type(role_1_tuple[0]) is Role)529 for p in role_1_tuple[0].permissions:530 assert_true(type(p) is Permission)531 role_2_tuple = self.module.create_role(role_2_name, role_2_description, pl2)532 assert_true(role_2_tuple[0] is not None)533 assert_true(role_2_tuple[1])534 assert_true(type(role_2_tuple[0]) is Role)535 for p in role_2_tuple[0].permissions:536 assert_true(type(p) is Permission)537 roles_list = list()538 roles_list.append(role_1_tuple[0])539 roles_list.append(role_2_tuple[0])540 new_user_tuple = self.module.create_user(username, password, first_name, family_name, email, roles_list)541 assert_true(new_user_tuple[0] is not None)542 assert_true(new_user_tuple[1])543 new_user = new_user_tuple[0]544 assert_true(type(new_user) is User)545 assert_true(type(new_user.roles) is list)546 for r in new_user.roles:547 assert_true(type(r) is Role)548 assert_true(type(r.permissions) is list)549 for p in r.permissions:550 assert_true(type(p) is Permission)551 user_found = self.module.get_user(new_user.id)552 assert_true(type(user_found) is User)553 assert_true(type(user_found.roles) is list)554 for r in user_found.roles:555 assert_true(type(r) is Role)556 assert_true(type(r.permissions) is list)557 for p in r.permissions:558 assert_true(type(p) is Permission)559 assert_true(user_found is not None)560 assert_equal(user_found.id, new_user.id)561 assert_equal(user_found.username, username)562 assert_equal(user_found.password, password)563 assert_equal(user_found.first_name, first_name)564 assert_equal(user_found.family_name, family_name)565 assert_equal(user_found.email, email)566 assert_equal(len(user_found.roles), len(new_user.roles))567 long_roles = len(user_found.roles)568 for index in range(long_roles):569 assert_equal(user_found.roles[index].id, new_user.roles[index].id)570 assert_equal(user_found.roles[index].name, new_user.roles[index].name)571 assert_equal(user_found.roles[index].description, new_user.roles[index].description)572 assert_equal(len(user_found.roles[index].permissions), len(new_user.roles[index].permissions))573 @log_function(logger)574 def test_17_set_case_type(self):575 case_type_name = 'case type name'576 case_type_desc = 'case type desc'577 case_type_tuple = self.module.create_case_type(case_type_name, case_type_desc)578 new_case_type = case_type_tuple[0]579 assert_true(new_case_type is not None)580 assert_true(case_type_tuple[1])581 assert_true(type(new_case_type) is CaseType)582 case_type_found = self.module.get_case_type(new_case_type.id)583 assert_true(case_type_found is not None)584 assert_true(type(case_type_found) is CaseType)585 assert_equal(case_type_found.id, new_case_type.id)586 assert_equal(case_type_found.name, case_type_name)587 assert_equal(case_type_found.description, case_type_desc)588 @log_function(logger)589 def test_18_set_case_status(self):590 case_status_name = 'case status name'591 case_status_desc = 'case status desc'592 case_status_tuple = self.module.create_case_status(case_status_name, case_status_desc)593 new_case_status = case_status_tuple[0]594 assert_true(new_case_status is not None)595 assert_true(case_status_tuple[1])596 assert_true(type(new_case_status) is CaseStatus)597 case_status_found = self.module.get_case_status(new_case_status.id)598 assert_true(case_status_found is not None)599 assert_true(type(case_status_found) is CaseStatus)600 assert_equal(case_status_found.id, new_case_status.id)601 assert_equal(case_status_found.name, case_status_name)602 assert_equal(case_status_found.description, case_status_desc)603 @log_function(logger)604 def test_19_set_case(self):605 formal_name = 'case formal name'606 friend_name = 'case friend name'607 creation_datetime = datetime.datetime.now()608 num_win = 1609 num_lin = 2610 num_ios = 3611 num_mal = 4612 num_pac = 5613 num_log = 6614 case_type_name = 'case type name'615 case_type_desc = 'case type desc'616 case_status_name = 'case status name'617 case_status_desc = 'case status desc'618 new_case_type_tuple = self.module.create_case_type(case_type_name, case_type_desc)619 new_case_type = new_case_type_tuple[0]620 assert_true(new_case_type is not None)621 assert_true(new_case_type_tuple[1])622 assert_true(type(new_case_type) is CaseType)623 new_case_status_tuple = self.module.create_case_status(case_status_name, case_status_desc)624 new_case_status = new_case_status_tuple[0]625 assert_true(new_case_status is not None)626 assert_true(new_case_status_tuple[1])627 assert_true(type(new_case_status) is CaseStatus)628 new_case_tuple = self.module.create_case(formal_name, friend_name, creation_datetime, num_win, num_lin,629 num_ios, num_mal, num_pac, num_log, new_case_type, new_case_status)630 new_case = new_case_tuple[0]631 assert_true(new_case is not None)632 assert_true(new_case_status)633 case_found = self.module.get_case(new_case.id)634 assert_true(case_found is not None)635 assert_true(type(case_found) is Case)636 assert_true(type(case_found.case_type) is CaseType)637 assert_true(type(case_found.case_status) is CaseStatus)638 assert_equal(case_found.id, new_case.id)639 assert_equal(case_found.formal_name, formal_name)640 assert_equal(case_found.friend_name, friend_name)641 assert_equal(case_found.creation_datetime, creation_datetime)642 assert_equal(case_found.num_win, num_win)643 assert_equal(case_found.num_lin, num_lin)644 assert_equal(case_found.num_ios, num_ios)645 assert_equal(case_found.num_mal, num_mal)646 assert_equal(case_found.num_pac, num_pac)647 assert_equal(case_found.num_log, num_log)648 assert_equal(case_found.case_type.id, new_case_type.id)649 assert_equal(case_found.case_type.name, case_type_name)650 assert_equal(case_found.case_type.description, case_type_desc)651 assert_equal(case_found.case_status.id, new_case_status.id)652 assert_equal(case_found.case_status.name, case_status_name)653 assert_equal(case_found.case_status.description, case_status_desc)654 @log_function(logger)655 def test_20_set_evidence(self):656 username = 'evidence username'657 password = 'evidence password'658 first_name = 'evidence first name'659 family_name = 'evidence family name'660 email = 'evidence email'661 role_1 = self.module.get_role(1)662 role_2 = self.module.get_role(2)663 roles_list = list()664 roles_list.append(role_1)665 roles_list.append(role_2)666 new_user_tuple = self.module.create_user(username, password, first_name, family_name, email, roles_list)667 new_user = new_user_tuple[0]668 assert_true(new_user is not None)669 assert_true(new_user_tuple[1])670 assert_true(type(new_user) is User)671 assert_true(type(new_user.roles) is list)672 for r in new_user.roles:673 assert_true(type(r) is Role)674 assert_true(type(r.permissions) is list)675 for p in r.permissions:676 assert_true(type(p) is Permission)677 alias = 'evidence alias'678 size = 89.65679 new_evidence_tuple = self.module.create_evidence(alias, size, new_user)680 new_evidence = new_evidence_tuple[0]681 assert_true(new_evidence is not None)682 assert_true(new_evidence_tuple[1])683 assert_true(type(new_evidence) is Evidence)684 assert_true(type(new_evidence.owner) is User)685 assert_true(type(new_evidence.owner.roles) is list)686 for r in new_evidence.owner.roles:687 assert_true(type(r) is Role)688 assert_true(type(r.permissions) is list)689 for p in r.permissions:690 assert_true(type(p) is Permission)691 evidence_found = self.module.get_evidence(new_evidence.id)692 assert_true(evidence_found is not None)693 assert_true(type(evidence_found) is Evidence)694 assert_true(type(evidence_found.owner) is User)695 assert_true(type(evidence_found.owner.roles) is list)696 for r in evidence_found.owner.roles:697 assert_true(type(r) is Role)698 assert_true(type(r.permissions) is list)699 for p in r.permissions:700 assert_true(type(p) is Permission)701 assert_equal(evidence_found.id, new_evidence.id)702 assert_equal(evidence_found.alias, alias)703 assert_equal(evidence_found.size, size)704 assert_equal(evidence_found.owner.id, new_evidence.owner.id)705 assert_equal(evidence_found.owner.username, username)706 assert_equal(evidence_found.owner.password, password)707 assert_equal(evidence_found.owner.first_name, first_name)708 assert_equal(evidence_found.owner.family_name, family_name)709 assert_equal(evidence_found.owner.email, email)710 assert_equal(len(evidence_found.owner.roles), len(new_evidence.owner.roles))711 @log_function(logger)712 def test_21_set_upload(self):713 user_found = self.module.get_user(1)714 assert_true(user_found is not None)715 assert_true(type(user_found) is User)716 assert_true(type(user_found.roles) is list)717 for r in user_found.roles:718 assert_true(type(r) is Role)719 assert_true(type(r.permissions) is list)720 for p in r.permissions:721 assert_true(type(p) is Permission)722 alias = 'evidence alias'723 evidence_size = 119.77724 new_evidence_tuple = self.module.create_evidence(alias, evidence_size, user_found)725 new_evidence = new_evidence_tuple[0]726 assert_true(new_evidence is not None)727 assert_true(new_evidence_tuple[1])728 assert_true(type(new_evidence) is Evidence)729 assert_true(type(new_evidence.owner) is User)730 assert_true(type(new_evidence.owner.roles) is list)731 for r in new_evidence.owner.roles:732 assert_true(type(r) is Role)733 assert_true(type(r.permissions) is list)734 for p in r.permissions:735 assert_true(type(p) is Permission)736 path = 'upload path'737 upload_size = 572.23738 upload_type = 'upload type'739 new_upload_tuple = self.module.create_upload(path, upload_size, upload_type, new_evidence)740 new_upload = new_upload_tuple[0]741 assert_true(new_upload is not None)742 assert_true(new_upload_tuple[1])743 assert_true(type(new_upload) is Upload)744 assert_true(type(new_upload.evidence) is Evidence)745 assert_true(type(new_upload.evidence.owner) is User)746 assert_true(type(new_upload.evidence.owner.roles) is list)747 for r in new_upload.evidence.owner.roles:748 assert_true(type(r) is Role)749 assert_true(type(r.permissions) is list)750 for p in r.permissions:751 assert_true(type(p) is Permission)752 upload_found = self.module.get_upload(new_upload.id)753 assert_true(upload_found is not None)754 assert_true(type(upload_found) is Upload)755 assert_true(type(upload_found.evidence) is Evidence)756 assert_true(type(upload_found.evidence.owner) is User)757 assert_true(type(upload_found.evidence.owner.roles) is list)758 for r in upload_found.evidence.owner.roles:759 assert_true(type(r) is Role)760 assert_true(type(r.permissions) is list)761 for p in r.permissions:762 assert_true(type(p) is Permission)763 assert_equal(upload_found.id, new_upload.id)764 assert_equal(upload_found.path, path)765 assert_equal(upload_found.size, upload_size)766 assert_equal(upload_found.type, upload_type)767 assert_equal(upload_found.evidence.id, new_upload.evidence.id)768 assert_equal(upload_found.evidence.alias, alias)769 assert_equal(upload_found.evidence.size, evidence_size)770 assert_equal(upload_found.evidence.owner.id, new_upload.evidence.owner.id)771 @log_function(logger)772 def test_22_set_file(self):773 upload_path = 'upload path'774 upload_size = 123.67775 upload_type = 'upload type'776 evidence_found = self.module.get_evidence(1)777 assert_true(evidence_found is not None)778 assert_true(type(evidence_found) is Evidence)779 assert_true(type(evidence_found.owner) is User)780 assert_true(type(evidence_found.owner.roles) is list)781 for r in evidence_found.owner.roles:782 assert_true(type(r) is Role)783 assert_true(type(r.permissions) is list)784 for p in r.permissions:785 assert_true(type(p) is Permission)786 new_upload_tuple = self.module.create_upload(upload_path, upload_size, upload_type, evidence_found)787 new_upload = new_upload_tuple[0]788 assert_true(new_upload is not None)789 assert_true(new_upload_tuple[1])790 assert_true(type(new_upload) is Upload)791 assert_true(type(new_upload.evidence) is Evidence)792 assert_true(type(new_upload.evidence.owner) is User)793 assert_true(type(new_upload.evidence.owner.roles) is list)794 for r in new_upload.evidence.owner.roles:795 assert_true(type(r) is Role)796 assert_true(type(r.permissions) is list)797 for p in r.permissions:798 assert_true(type(p) is Permission)799 file_path = 'file path'800 file_size = 0.23801 name = 'file name'802 hash_md5 = 'file hash md5'803 hash_sha256 = 'file hash sha256'804 new_file_tuple = self.module.create_file(file_path, file_size, name, hash_md5, hash_sha256, new_upload)805 new_file = new_file_tuple[0]806 assert_true(new_file is not None)807 assert_true(new_file_tuple[1])808 assert_true(type(new_file) is File)809 assert_true(type(new_file.upload) is Upload)810 assert_true(type(new_file.upload.evidence) is Evidence)811 assert_true(type(new_file.upload.evidence.owner) is User)812 assert_true(type(new_file.upload.evidence.owner.roles) is list)813 for r in new_file.upload.evidence.owner.roles:814 assert_true(type(r) is Role)815 assert_true(type(r.permissions) is list)816 for p in r.permissions:817 assert_true(type(p) is Permission)818 file_found = self.module.get_file(new_file.id)819 assert_true(file_found is not None)820 assert_true(type(file_found) is File)821 assert_true(type(file_found.upload) is Upload)822 assert_true(type(file_found.upload.evidence) is Evidence)823 assert_true(type(file_found.upload.evidence.owner) is User)824 assert_true(type(file_found.upload.evidence.owner.roles) is list)825 for r in file_found.upload.evidence.owner.roles:826 assert_true(type(r) is Role)827 assert_true(type(r.permissions) is list)828 for p in r.permissions:829 assert_true(type(p) is Permission)830 assert_equal(file_found.id, new_file.id)831 assert_equal(file_found.path, file_path)832 assert_equal(file_found.size, file_size)833 assert_equal(file_found.name, name)834 assert_equal(file_found.hash_md5, hash_md5)835 assert_equal(file_found.hash_sha256, hash_sha256)836 assert_equal(file_found.upload.id, new_file.upload.id)837 assert_equal(file_found.upload.path, upload_path)838 assert_equal(file_found.upload.size, upload_size)839 assert_equal(file_found.upload.type, upload_type)840 assert_equal(file_found.upload.evidence.id, new_file.upload.evidence.id)841 @log_function(logger)842 def test_23_set_entity(self):843 entity_name = 'entity name'844 entity_desc = 'entity desc'845 new_entity_tuple = self.module.create_entity(entity_name, entity_desc)846 new_entity = new_entity_tuple[0]847 assert_true(new_entity is not None)848 assert_true(new_entity_tuple[1])849 assert_true(type(new_entity) is Entity)850 entity_found = self.module.get_entity(new_entity.id)851 assert_true(entity_found is not None)852 assert_true(type(entity_found) is Entity)853 assert_equal(entity_found.id, new_entity.id)854 assert_equal(entity_found.name, entity_name)855 assert_equal(entity_found.description, entity_desc)856 @log_function(logger)857 def test_24_set_instance(self):858 entity_name = 'entity name'859 entity_desc = 'entity desc'860 new_entity_tuple = self.module.create_entity(entity_name, entity_desc)861 new_entity = new_entity_tuple[0]862 assert_true(new_entity is not None)863 assert_true(new_entity_tuple[1])864 assert_true(type(new_entity) is Entity)865 instance_name = 'instance name'866 new_instance_tuple = self.module.create_instance(instance_name, new_entity)867 new_instance = new_instance_tuple[0]868 assert_true(new_instance is not None)869 assert_true(new_instance_tuple[1])870 assert_true(type(new_instance) is Instance)871 assert_true(type(new_instance.entity) is Entity)872 instance_found = self.module.get_instance(new_instance.id)873 assert_true(instance_found is not None)874 assert_true(type(instance_found) is Instance)875 assert_true(type(instance_found.entity) is Entity)876 assert_equal(instance_found.id, new_instance.id)877 assert_equal(instance_found.name, instance_name)878 assert_equal(instance_found.entity.id, new_entity.id)879 assert_equal(instance_found.entity.name, entity_name)880 assert_equal(instance_found.entity.description, entity_desc)881 @log_function(logger)882 def test_25_set_property(self):883 ent_name = 'ent name'884 ent_desc = 'ent desc'885 new_entity_tuple = self.module.create_entity(ent_name, ent_desc)886 new_entity = new_entity_tuple[0]887 assert_true(new_entity is not None)888 assert_true(new_entity_tuple[1])889 assert_true(type(new_entity) is Entity)890 pro_name = 'pro_name'891 pro_desc = 'pro_desc'892 new_property_tuple = self.module.create_property(pro_name, pro_desc, new_entity)893 new_property = new_property_tuple[0]894 assert_true(new_property is not None)895 assert_true(new_property_tuple[1])896 assert_true(type(new_property) is Property)897 assert_true(type(new_property.entity) is Entity)898 property_found = self.module.get_property(new_property.id)899 assert_true(property_found is not None)900 assert_true(type(property_found) is Property)901 assert_true(type(property_found.entity) is Entity)902 assert_equal(property_found.id, new_property.id)903 assert_equal(property_found.name, pro_name)904 assert_equal(property_found.description, pro_desc)905 assert_equal(property_found.entity.id, new_property.entity.id)906 assert_equal(property_found.entity.name, ent_name)907 assert_equal(property_found.entity.description, ent_desc)908 @log_function(logger)909 def test_26_set_value_ok(self):910 entity = self.module.get_entity(1)911 assert_true(type(entity) is Entity)912 pro_name = 'pro name'913 pro_desc = 'pro desc'914 new_property_tuple = self.module.create_property(pro_name, pro_desc, entity)915 new_property = new_property_tuple[0]916 assert_true(new_property is not None)917 assert_true(new_property_tuple[1])918 assert_true(type(new_property) is Property)919 assert_true(type(new_property.entity) is Entity)920 ins_name = 'instance name'921 new_instance_tuple = self.module.create_instance(ins_name, entity)922 new_instance = new_instance_tuple[0]923 assert_true(new_instance is not None)924 assert_true(new_instance_tuple[1])925 assert_true(type(new_instance) is Instance)926 assert_true(type(new_instance.entity) is Entity)927 value = 'new value'928 new_value_tuple = self.module.create_value(new_property, new_instance, value)929 new_value = new_value_tuple[0]930 assert_true(new_value is not None)931 assert_true(new_value_tuple[1])932 assert_true(type(new_value) is Value)933 assert_true(type(new_value.property) is Property)934 assert_true(type(new_value.instance) is Instance)935 value_found = self.module.get_value(new_value.id)936 assert_true(type(value_found) is Value)937 assert_true(type(value_found.property) is Property)938 assert_true(type(value_found.instance) is Instance)939 assert_equal(value_found.id, new_value.id)940 assert_equal(value_found.value, value)941 assert_equal(value_found.property.id, new_property.id)942 assert_equal(value_found.property.name, pro_name)943 assert_equal(value_found.property.description, pro_desc)944 assert_equal(value_found.instance.id, new_instance.id)945 assert_equal(value_found.instance.name, ins_name)946 @log_function(logger)947 def test_27_set_value_fail(self):948 entity_pro = self.module.get_entity(1)949 assert_true(type(entity_pro) is Entity)950 entity_ins = self.module.get_entity(2)951 assert_true(type(entity_ins) is Entity)952 pro_name = 'pro name fail'953 pro_desc = 'pro desc fail'954 new_property_tuple = self.module.create_property(pro_name, pro_desc, entity_pro)955 new_property = new_property_tuple[0]956 assert_true(new_property is not None)957 assert_true(new_property_tuple[1])958 assert_true(type(new_property) is Property)959 assert_true(type(new_property.entity) is Entity)960 ins_name = 'instance name fail'961 new_instance_tuple = self.module.create_instance(ins_name, entity_ins)962 new_instance = new_instance_tuple[0]963 assert_true(new_instance is not None)964 assert_true(new_instance_tuple[1])965 assert_true(type(new_instance) is Instance)966 assert_true(type(new_instance.entity) is Entity)967 value = 'new value'968 new_value_tuple = self.module.create_value(new_property, new_instance, value)969 new_value = new_value_tuple[0]970 assert_true(new_value is None)971 assert_true(new_value_tuple[1] == False)972 @log_function(logger)973 def test_28_get_user_id_ok(self):974 username = 'username si'975 password = 'password si'976 first_name = 'first name'977 family_name = 'family name'978 email = 'mail'979 roles_list = list()980 role = self.module.get_role(1)981 roles_list.append(role)982 new_user_tuple = self.module.create_user(username, password, first_name, family_name, email, roles_list)983 new_user_id = new_user_tuple[0].id984 login_user = new_user_tuple[0].username985 login_pass = new_user_tuple[0].password986 found_user_id = self.module.get_user_id(login_user, login_pass)987 assert_true(type(found_user_id) is not None)988 assert_true(type(found_user_id) is int)989 assert_equal(new_user_id, found_user_id)990 @log_function(logger)991 def test_28_get_user_id_ok(self):992 username = 'username no'993 password = 'password no'994 first_name = 'first name'995 family_name = 'family name'996 email = 'mail'997 roles_list = list()998 role = self.module.get_role(2)999 roles_list.append(role)1000 new_user_tuple = self.module.create_user(username, password, first_name, family_name, email, roles_list)1001 login_user = new_user_tuple[0].username + 'algo'1002 login_pass = new_user_tuple[0].password + 'algo'1003 found_user_id = self.module.get_user_id(login_user, login_pass)...

Full Screen

Full Screen

historical_tests.py

Source:historical_tests.py Github

copy

Full Screen

...25 # Nodes26 def test_add_remove_node(self):27 G = self.G()28 G.add_node('A')29 assert_true(G.has_node('A'))30 G.remove_node('A')31 assert_false(G.has_node('A'))32 def test_nonhashable_node(self):33 # Test if a non-hashable object is in the Graph. A python dict will34 # raise a TypeError, but for a Graph class a simple False should be35 # returned (see Graph __contains__). If it cannot be a node then it is36 # not a node.37 G = self.G()38 assert_false(G.has_node(['A']))39 assert_false(G.has_node({'A': 1}))40 def test_add_nodes_from(self):41 G = self.G()42 G.add_nodes_from(list("ABCDEFGHIJKL"))43 assert_true(G.has_node("L"))44 G.remove_nodes_from(['H', 'I', 'J', 'K', 'L'])45 G.add_nodes_from([1, 2, 3, 4])46 assert_equal(sorted(G.nodes(), key=str),47 [1, 2, 3, 4, 'A', 'B', 'C', 'D', 'E', 'F', 'G'])48 # test __iter__49 assert_equal(sorted(G, key=str),50 [1, 2, 3, 4, 'A', 'B', 'C', 'D', 'E', 'F', 'G'])51 def test_contains(self):52 G = self.G()53 G.add_node('A')54 assert_true('A' in G)55 assert_false([] in G) # never raise a Key or TypeError in this test56 assert_false({1: 1} in G)57 def test_add_remove(self):58 # Test add_node and remove_node acting for various nbunch59 G = self.G()60 G.add_node('m')61 assert_true(G.has_node('m'))62 G.add_node('m') # no complaints63 assert_raises(nx.NetworkXError, G.remove_node, 'j')64 G.remove_node('m')65 assert_equal(list(G), [])66 def test_nbunch_is_list(self):67 G = self.G()68 G.add_nodes_from(list("ABCD"))69 G.add_nodes_from(self.P3) # add nbunch of nodes (nbunch=Graph)70 assert_equal(sorted(G.nodes(), key=str),71 [1, 2, 3, 'A', 'B', 'C', 'D'])72 G.remove_nodes_from(self.P3) # remove nbunch of nodes (nbunch=Graph)73 assert_equal(sorted(G.nodes(), key=str),74 ['A', 'B', 'C', 'D'])75 def test_nbunch_is_set(self):76 G = self.G()77 nbunch = set("ABCDEFGHIJKL")78 G.add_nodes_from(nbunch)79 assert_true(G.has_node("L"))80 def test_nbunch_dict(self):81 # nbunch is a dict with nodes as keys82 G = self.G()83 nbunch = set("ABCDEFGHIJKL")84 G.add_nodes_from(nbunch)85 nbunch = {'I': "foo", 'J': 2, 'K': True, 'L': "spam"}86 G.remove_nodes_from(nbunch)87 assert_true(sorted(G.nodes(), key=str),88 ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H'])89 def test_nbunch_iterator(self):90 G = self.G()91 G.add_nodes_from(['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H'])92 n_iter = self.P3.nodes()93 G.add_nodes_from(n_iter)94 assert_equal(sorted(G.nodes(), key=str),95 [1, 2, 3, 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H'])96 n_iter = self.P3.nodes() # rebuild same iterator97 G.remove_nodes_from(n_iter) # remove nbunch of nodes (nbunch=iterator)98 assert_equal(sorted(G.nodes(), key=str),99 ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H'])100 def test_nbunch_graph(self):101 G = self.G()102 G.add_nodes_from(['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H'])103 nbunch = self.K3104 G.add_nodes_from(nbunch)105 assert_true(sorted(G.nodes(), key=str),106 [1, 2, 3, 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H'])107 # Edges108 def test_add_edge(self):109 G = self.G()110 assert_raises(TypeError, G.add_edge, 'A')111 G.add_edge('A', 'B') # testing add_edge()112 G.add_edge('A', 'B') # should fail silently113 assert_true(G.has_edge('A', 'B'))114 assert_false(G.has_edge('A', 'C'))115 assert_true(G.has_edge(*('A', 'B')))116 if G.is_directed():117 assert_false(G.has_edge('B', 'A'))118 else:119 # G is undirected, so B->A is an edge120 assert_true(G.has_edge('B', 'A'))121 G.add_edge('A', 'C') # test directedness122 G.add_edge('C', 'A')123 G.remove_edge('C', 'A')124 if G.is_directed():125 assert_true(G.has_edge('A', 'C'))126 else:127 assert_false(G.has_edge('A', 'C'))128 assert_false(G.has_edge('C', 'A'))129 def test_self_loop(self):130 G = self.G()131 G.add_edge('A', 'A') # test self loops132 assert_true(G.has_edge('A', 'A'))133 G.remove_edge('A', 'A')134 G.add_edge('X', 'X')135 assert_true(G.has_node('X'))136 G.remove_node('X')137 G.add_edge('A', 'Z') # should add the node silently138 assert_true(G.has_node('Z'))139 def test_add_edges_from(self):140 G = self.G()141 G.add_edges_from([('B', 'C')]) # test add_edges_from()142 assert_true(G.has_edge('B', 'C'))143 if G.is_directed():144 assert_false(G.has_edge('C', 'B'))145 else:146 assert_true(G.has_edge('C', 'B')) # undirected147 G.add_edges_from([('D', 'F'), ('B', 'D')])148 assert_true(G.has_edge('D', 'F'))149 assert_true(G.has_edge('B', 'D'))150 if G.is_directed():151 assert_false(G.has_edge('D', 'B'))152 else:153 assert_true(G.has_edge('D', 'B')) # undirected154 def test_add_edges_from2(self):155 G = self.G()156 # after failing silently, should add 2nd edge157 G.add_edges_from([tuple('IJ'), list('KK'), tuple('JK')])158 assert_true(G.has_edge(*('I', 'J')))159 assert_true(G.has_edge(*('K', 'K')))160 assert_true(G.has_edge(*('J', 'K')))161 if G.is_directed():162 assert_false(G.has_edge(*('K', 'J')))163 else:164 assert_true(G.has_edge(*('K', 'J')))165 def test_add_edges_from3(self):166 G = self.G()167 G.add_edges_from(zip(list('ACD'), list('CDE')))168 assert_true(G.has_edge('D', 'E'))169 assert_false(G.has_edge('E', 'C'))170 def test_remove_edge(self):171 G = self.G()172 G.add_nodes_from([1, 2, 3, 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H'])173 G.add_edges_from(zip(list('MNOP'), list('NOPM')))174 assert_true(G.has_edge('O', 'P'))175 assert_true(G.has_edge('P', 'M'))176 G.remove_node('P') # tests remove_node()'s handling of edges.177 assert_false(G.has_edge('P', 'M'))178 assert_raises(TypeError, G.remove_edge, 'M')179 G.add_edge('N', 'M')180 assert_true(G.has_edge('M', 'N'))181 G.remove_edge('M', 'N')182 assert_false(G.has_edge('M', 'N'))183 # self loop fails silently184 G.remove_edges_from([list('HI'), list('DF'),185 tuple('KK'), tuple('JK')])186 assert_false(G.has_edge('H', 'I'))187 assert_false(G.has_edge('J', 'K'))188 G.remove_edges_from([list('IJ'), list('KK'), list('JK')])189 assert_false(G.has_edge('I', 'J'))190 G.remove_nodes_from(set('ZEFHIMNO'))191 G.add_edge('J', 'K')192 def test_edges_nbunch(self):193 # Test G.edges(nbunch) with various forms of nbunch194 G = self.G()195 G.add_edges_from([('A', 'B'), ('A', 'C'), ('B', 'D'),196 ('C', 'B'), ('C', 'D')])197 # node not in nbunch should be quietly ignored198 assert_raises(nx.NetworkXError, G.edges, 6)199 assert_equals(list(G.edges('Z')), []) # iterable non-node200 # nbunch can be an empty list201 assert_equals(list(G.edges([])), [])202 if G.is_directed():203 elist = [('A', 'B'), ('A', 'C'), ('B', 'D')]204 else:205 elist = [('A', 'B'), ('A', 'C'), ('B', 'C'), ('B', 'D')]206 # nbunch can be a list207 assert_edges_equal(list(G.edges(['A', 'B'])), elist)208 # nbunch can be a set209 assert_edges_equal(G.edges(set(['A', 'B'])), elist)210 # nbunch can be a graph211 G1 = self.G()212 G1.add_nodes_from('AB')213 assert_edges_equal(G.edges(G1), elist)214 # nbunch can be a dict with nodes as keys215 ndict = {'A': "thing1", 'B': "thing2"}216 assert_edges_equal(G.edges(ndict), elist)217 # nbunch can be a single node218 assert_edges_equal(list(G.edges('A')), [('A', 'B'), ('A', 'C')])219 assert_nodes_equal(sorted(G), ['A', 'B', 'C', 'D'])220 # nbunch can be nothing (whole graph)221 assert_edges_equal(222 list(G.edges()),223 [('A', 'B'), ('A', 'C'), ('B', 'D'), ('C', 'B'), ('C', 'D')]224 )225 def test_degree(self):226 G = self.G()227 G.add_edges_from([('A', 'B'), ('A', 'C'), ('B', 'D'),228 ('C', 'B'), ('C', 'D')])229 assert_equal(G.degree('A'), 2)230 # degree of single node in iterable container must return dict231 assert_equal(list(G.degree(['A'])), [('A', 2)])232 assert_equal(sorted(d for n, d in G.degree(['A', 'B'])), [2, 3])233 assert_equal(sorted(d for n, d in G.degree()), [2, 2, 3, 3])234 def test_degree2(self):235 H = self.G()236 H.add_edges_from([(1, 24), (1, 2)])237 assert_equal(sorted(d for n, d in H.degree([1, 24])), [1, 2])238 def test_degree_graph(self):239 P3 = nx.path_graph(3)240 P5 = nx.path_graph(5)241 # silently ignore nodes not in P3242 assert_equal(dict(d for n, d in P3.degree(['A', 'B'])), {})243 # nbunch can be a graph244 assert_equal(sorted(d for n, d in P5.degree(P3)), [1, 2, 2])245 # nbunch can be a graph that's way too big246 assert_equal(sorted(d for n, d in P3.degree(P5)), [1, 1, 2])247 assert_equal(list(P5.degree([])), [])248 assert_equal(dict(P5.degree([])), {})249 def test_null(self):250 null = nx.null_graph()251 assert_equal(list(null.degree()), [])252 assert_equal(dict(null.degree()), {})253 def test_order_size(self):254 G = self.G()255 G.add_edges_from([('A', 'B'), ('A', 'C'), ('B', 'D'),256 ('C', 'B'), ('C', 'D')])257 assert_equal(G.order(), 4)258 assert_equal(G.size(), 5)259 assert_equal(G.number_of_edges(), 5)260 assert_equal(G.number_of_edges('A', 'B'), 1)261 assert_equal(G.number_of_edges('A', 'D'), 0)262 def test_copy(self):263 G = self.G()264 H = G.copy() # copy265 assert_equal(H.adj, G.adj)266 assert_equal(H.name, G.name)267 assert_not_equal(H, G)268 def test_subgraph(self):269 G = self.G()270 G.add_edges_from([('A', 'B'), ('A', 'C'), ('B', 'D'),271 ('C', 'B'), ('C', 'D')])272 SG = G.subgraph(['A', 'B', 'D'])273 assert_nodes_equal(list(SG), ['A', 'B', 'D'])274 assert_edges_equal(list(SG.edges()), [('A', 'B'), ('B', 'D')])275 def test_to_directed(self):276 G = self.G()277 if not G.is_directed():278 G.add_edges_from([('A', 'B'), ('A', 'C'), ('B', 'D'),279 ('C', 'B'), ('C', 'D')])280 DG = G.to_directed()281 assert_not_equal(DG, G) # directed copy or copy282 assert_true(DG.is_directed())283 assert_equal(DG.name, G.name)284 assert_equal(DG.adj, G.adj)285 assert_equal(sorted(DG.out_edges(list('AB'))),286 [('A', 'B'), ('A', 'C'), ('B', 'A'),287 ('B', 'C'), ('B', 'D')])288 DG.remove_edge('A', 'B')289 assert_true(DG.has_edge('B', 'A')) # this removes B-A but not A-B290 assert_false(DG.has_edge('A', 'B'))291 def test_to_undirected(self):292 G = self.G()293 if G.is_directed():294 G.add_edges_from([('A', 'B'), ('A', 'C'), ('B', 'D'),295 ('C', 'B'), ('C', 'D')])296 UG = G.to_undirected() # to_undirected297 assert_not_equal(UG, G)298 assert_false(UG.is_directed())299 assert_true(G.is_directed())300 assert_equal(UG.name, G.name)301 assert_not_equal(UG.adj, G.adj)302 assert_equal(sorted(UG.edges(list('AB'))),303 [('A', 'B'), ('A', 'C'), ('B', 'C'), ('B', 'D')])304 assert_equal(sorted(UG.edges(['A', 'B'])),305 [('A', 'B'), ('A', 'C'), ('B', 'C'), ('B', 'D')])306 UG.remove_edge('A', 'B')307 assert_false(UG.has_edge('B', 'A'))308 assert_false(UG.has_edge('A', 'B'))309 def test_neighbors(self):310 G = self.G()311 G.add_edges_from([('A', 'B'), ('A', 'C'), ('B', 'D'),312 ('C', 'B'), ('C', 'D')])313 G.add_nodes_from('GJK')314 assert_equal(sorted(G['A']), ['B', 'C'])315 assert_equal(sorted(G.neighbors('A')), ['B', 'C'])316 assert_equal(sorted(G.neighbors('A')), ['B', 'C'])317 assert_equal(sorted(G.neighbors('G')), [])318 assert_raises(nx.NetworkXError, G.neighbors, 'j')319 def test_iterators(self):320 G = self.G()321 G.add_edges_from([('A', 'B'), ('A', 'C'), ('B', 'D'),322 ('C', 'B'), ('C', 'D')])323 G.add_nodes_from('GJK')324 assert_equal(sorted(G.nodes()),325 ['A', 'B', 'C', 'D', 'G', 'J', 'K'])326 assert_edges_equal(G.edges(),327 [('A', 'B'), ('A', 'C'), ('B', 'D'), ('C', 'B'), ('C', 'D')])328 assert_equal(sorted([v for k, v in G.degree()]),329 [0, 0, 0, 2, 2, 3, 3])330 assert_equal(sorted(G.degree(), key=str),331 [('A', 2), ('B', 3), ('C', 3), ('D', 2),332 ('G', 0), ('J', 0), ('K', 0)])333 assert_equal(sorted(G.neighbors('A')), ['B', 'C'])334 assert_raises(nx.NetworkXError, G.neighbors, 'X')335 G.clear()336 assert_equal(nx.number_of_nodes(G), 0)337 assert_equal(nx.number_of_edges(G), 0)338 def test_null_subgraph(self):339 # Subgraph of a null graph is a null graph340 nullgraph = nx.null_graph()341 G = nx.null_graph()342 H = G.subgraph([])343 assert_true(nx.is_isomorphic(H, nullgraph))344 def test_empty_subgraph(self):345 # Subgraph of an empty graph is an empty graph. test 1346 nullgraph = nx.null_graph()347 E5 = nx.empty_graph(5)348 E10 = nx.empty_graph(10)349 H = E10.subgraph([])350 assert_true(nx.is_isomorphic(H, nullgraph))351 H = E10.subgraph([1, 2, 3, 4, 5])352 assert_true(nx.is_isomorphic(H, E5))353 def test_complete_subgraph(self):354 # Subgraph of a complete graph is a complete graph355 K1 = nx.complete_graph(1)356 K3 = nx.complete_graph(3)357 K5 = nx.complete_graph(5)358 H = K5.subgraph([1, 2, 3])359 assert_true(nx.is_isomorphic(H, K3))360 def test_subgraph_nbunch(self):361 nullgraph = nx.null_graph()362 K1 = nx.complete_graph(1)363 K3 = nx.complete_graph(3)364 K5 = nx.complete_graph(5)365 # Test G.subgraph(nbunch), where nbunch is a single node366 H = K5.subgraph(1)367 assert_true(nx.is_isomorphic(H, K1))368 # Test G.subgraph(nbunch), where nbunch is a set369 H = K5.subgraph(set([1]))370 assert_true(nx.is_isomorphic(H, K1))371 # Test G.subgraph(nbunch), where nbunch is an iterator372 H = K5.subgraph(iter(K3))373 assert_true(nx.is_isomorphic(H, K3))374 # Test G.subgraph(nbunch), where nbunch is another graph375 H = K5.subgraph(K3)376 assert_true(nx.is_isomorphic(H, K3))377 H = K5.subgraph([9])378 assert_true(nx.is_isomorphic(H, nullgraph))379 def test_node_tuple_issue(self):380 H = self.G()381 # Test error handling of tuple as a node382 assert_raises(nx.NetworkXError, H.remove_node, (1, 2))383 H.remove_nodes_from([(1, 2)]) # no error...

Full Screen

Full Screen

test_classic.py

Source:test_classic.py Github

copy

Full Screen

...16 # balanced_tree(r,h) is a tree with (r**(h+1)-1)/(r-1) edges17 for r,h in [(2,2),(3,3),(6,2)]:18 t=balanced_tree(r,h)19 order=t.order()20 assert_true(order==(r**(h+1)-1)/(r-1))21 assert_true(is_connected(t)) 22 assert_true(t.size()==order-1)23 dh = degree_histogram(t)24 assert_equal(dh[0],0) # no nodes of 0 25 assert_equal(dh[1],r**h) # nodes of degree 1 are leaves26 assert_equal(dh[r],1) # root is degree r27 assert_equal(dh[r+1],order-r**h-1)# everyone else is degree r+128 assert_equal(len(dh),r+2)2930 def test_balanced_tree_star(self):31 # balanced_tree(r,1) is the r-star32 t=balanced_tree(r=2,h=1)33 assert_true(is_isomorphic(t,star_graph(2)))34 t=balanced_tree(r=5,h=1)35 assert_true(is_isomorphic(t,star_graph(5)))36 t=balanced_tree(r=10,h=1)37 assert_true(is_isomorphic(t,star_graph(10)))3839 def test_full_rary_tree(self):40 r=241 n=942 t=full_rary_tree(r,n)43 assert_equal(t.order(),n)44 assert_true(is_connected(t))45 dh = degree_histogram(t)46 assert_equal(dh[0],0) # no nodes of 0 47 assert_equal(dh[1],5) # nodes of degree 1 are leaves48 assert_equal(dh[r],1) # root is degree r49 assert_equal(dh[r+1],9-5-1) # everyone else is degree r+150 assert_equal(len(dh),r+2)5152 def test_full_rary_tree_balanced(self):53 t=full_rary_tree(2,15)54 th=balanced_tree(2,3)55 assert_true(is_isomorphic(t,th))5657 def test_full_rary_tree_path(self):58 t=full_rary_tree(1,10)59 assert_true(is_isomorphic(t,path_graph(10)))6061 def test_full_rary_tree_empty(self):62 t=full_rary_tree(0,10)63 assert_true(is_isomorphic(t,empty_graph(10)))64 t=full_rary_tree(3,0)65 assert_true(is_isomorphic(t,empty_graph(0)))6667 def test_full_rary_tree_3_20(self):68 t=full_rary_tree(3,20)69 assert_equal(t.order(),20)7071 def test_barbell_graph(self):72 # number of nodes = 2*m1 + m2 (2 m1-complete graphs + m2-path + 2 edges)73 # number of edges = 2*(number_of_edges(m1-complete graph) + m2 + 174 m1=3; m2=575 b=barbell_graph(m1,m2)76 assert_true(number_of_nodes(b)==2*m1+m2)77 assert_true(number_of_edges(b)==m1*(m1-1) + m2 + 1)78 assert_equal(b.name, 'barbell_graph(3,5)')7980 m1=4; m2=1081 b=barbell_graph(m1,m2)82 assert_true(number_of_nodes(b)==2*m1+m2)83 assert_true(number_of_edges(b)==m1*(m1-1) + m2 + 1)84 assert_equal(b.name, 'barbell_graph(4,10)')8586 m1=3; m2=2087 b=barbell_graph(m1,m2)88 assert_true(number_of_nodes(b)==2*m1+m2)89 assert_true(number_of_edges(b)==m1*(m1-1) + m2 + 1)90 assert_equal(b.name, 'barbell_graph(3,20)')9192 # Raise NetworkXError if m1<293 m1=1; m2=2094 assert_raises(networkx.exception.NetworkXError, barbell_graph, m1, m2)9596 # Raise NetworkXError if m2<097 m1=5; m2=-298 assert_raises(networkx.exception.NetworkXError, barbell_graph, m1, m2)99100 # barbell_graph(2,m) = path_graph(m+4)101 m1=2; m2=5102 b=barbell_graph(m1,m2)103 assert_true(is_isomorphic(b, path_graph(m2+4)))104105 m1=2; m2=10106 b=barbell_graph(m1,m2)107 assert_true(is_isomorphic(b, path_graph(m2+4)))108109 m1=2; m2=20110 b=barbell_graph(m1,m2)111 assert_true(is_isomorphic(b, path_graph(m2+4)))112113 assert_raises(networkx.exception.NetworkXError, barbell_graph, m1, m2, 114 create_using=DiGraph())115 116 mb=barbell_graph(m1, m2, create_using=MultiGraph())117 assert_true(mb.edges()==b.edges())118119 def test_complete_graph(self):120 # complete_graph(m) is a connected graph with 121 # m nodes and m*(m+1)/2 edges122 for m in [0, 1, 3, 5]:123 g = complete_graph(m)124 assert_true(number_of_nodes(g) == m)125 assert_true(number_of_edges(g) == m * (m - 1) // 2)126127 128 mg=complete_graph(m, create_using=MultiGraph())129 assert_true(mg.edges()==g.edges())130131 def test_complete_digraph(self):132 # complete_graph(m) is a connected graph with 133 # m nodes and m*(m+1)/2 edges134 for m in [0, 1, 3, 5]:135 g = complete_graph(m,create_using=nx.DiGraph())136 assert_true(number_of_nodes(g) == m)137 assert_true(number_of_edges(g) == m * (m - 1))138139 def test_complete_bipartite_graph(self):140 G=complete_bipartite_graph(0,0)141 assert_true(is_isomorphic( G, null_graph() ))142 143 for i in [1, 5]:144 G=complete_bipartite_graph(i,0)145 assert_true(is_isomorphic( G, empty_graph(i) ))146 G=complete_bipartite_graph(0,i)147 assert_true(is_isomorphic( G, empty_graph(i) ))148149 G=complete_bipartite_graph(2,2)150 assert_true(is_isomorphic( G, cycle_graph(4) ))151152 G=complete_bipartite_graph(1,5)153 assert_true(is_isomorphic( G, star_graph(5) ))154155 G=complete_bipartite_graph(5,1)156 assert_true(is_isomorphic( G, star_graph(5) ))157158 # complete_bipartite_graph(m1,m2) is a connected graph with159 # m1+m2 nodes and m1*m2 edges160 for m1, m2 in [(5, 11), (7, 3)]:161 G=complete_bipartite_graph(m1,m2)162 assert_equal(number_of_nodes(G), m1 + m2)163 assert_equal(number_of_edges(G), m1 * m2)164165 assert_raises(networkx.exception.NetworkXError,166 complete_bipartite_graph, 7, 3, create_using=DiGraph())167 168 mG=complete_bipartite_graph(7, 3, create_using=MultiGraph())169 assert_equal(mG.edges(), G.edges())170171 def test_circular_ladder_graph(self):172 G=circular_ladder_graph(5)173 assert_raises(networkx.exception.NetworkXError, circular_ladder_graph,174 5, create_using=DiGraph())175 mG=circular_ladder_graph(5, create_using=MultiGraph())176 assert_equal(mG.edges(), G.edges())177178 def test_cycle_graph(self):179 G=cycle_graph(4)180 assert_equal(sorted(G.edges()), [(0, 1), (0, 3), (1, 2), (2, 3)])181 mG=cycle_graph(4, create_using=MultiGraph())182 assert_equal(sorted(mG.edges()), [(0, 1), (0, 3), (1, 2), (2, 3)])183 G=cycle_graph(4, create_using=DiGraph())184 assert_false(G.has_edge(2,1))185 assert_true(G.has_edge(1,2))186 187 def test_dorogovtsev_goltsev_mendes_graph(self):188 G=dorogovtsev_goltsev_mendes_graph(0)189 assert_equal(G.edges(), [(0, 1)])190 assert_equal(G.nodes(), [0, 1])191 G=dorogovtsev_goltsev_mendes_graph(1)192 assert_equal(G.edges(), [(0, 1), (0, 2), (1, 2)])193 assert_equal(average_clustering(G), 1.0)194 assert_equal(list(triangles(G).values()), [1, 1, 1])195 G=dorogovtsev_goltsev_mendes_graph(10)196 assert_equal(number_of_nodes(G), 29526)197 assert_equal(number_of_edges(G), 59049)198 assert_equal(G.degree(0), 1024)199 assert_equal(G.degree(1), 1024)200 assert_equal(G.degree(2), 1024)201202 assert_raises(networkx.exception.NetworkXError,203 dorogovtsev_goltsev_mendes_graph, 7,204 create_using=DiGraph())205 assert_raises(networkx.exception.NetworkXError,206 dorogovtsev_goltsev_mendes_graph, 7,207 create_using=MultiGraph())208209 def test_empty_graph(self):210 G=empty_graph()211 assert_equal(number_of_nodes(G), 0)212 G=empty_graph(42)213 assert_equal(number_of_nodes(G), 42)214 assert_equal(number_of_edges(G), 0)215 assert_equal(G.name, 'empty_graph(42)')216217 # create empty digraph218 G=empty_graph(42,create_using=DiGraph(name="duh"))219 assert_equal(number_of_nodes(G), 42)220 assert_equal(number_of_edges(G), 0)221 assert_equal(G.name, 'empty_graph(42)')222 assert_true(isinstance(G,DiGraph))223224 # create empty multigraph225 G=empty_graph(42,create_using=MultiGraph(name="duh"))226 assert_equal(number_of_nodes(G), 42)227 assert_equal(number_of_edges(G), 0)228 assert_equal(G.name, 'empty_graph(42)')229 assert_true(isinstance(G,MultiGraph))230 231 # create empty graph from another232 pete=petersen_graph()233 G=empty_graph(42,create_using=pete)234 assert_equal(number_of_nodes(G), 42)235 assert_equal(number_of_edges(G), 0)236 assert_equal(G.name, 'empty_graph(42)')237 assert_true(isinstance(G,Graph))238 239 def test_grid_2d_graph(self):240 n=5;m=6241 G=grid_2d_graph(n,m)242 assert_equal(number_of_nodes(G), n*m)243 assert_equal(degree_histogram(G), [0,0,4,2*(n+m)-8,(n-2)*(m-2)])244 DG=grid_2d_graph(n,m, create_using=DiGraph())245 assert_equal(DG.succ, G.adj)246 assert_equal(DG.pred, G.adj)247 MG=grid_2d_graph(n,m, create_using=MultiGraph())248 assert_equal(MG.edges(), G.edges())249 250 def test_grid_graph(self):251 """grid_graph([n,m]) is a connected simple graph with the252 following properties:253 number_of_nodes=n*m254 degree_histogram=[0,0,4,2*(n+m)-8,(n-2)*(m-2)]255 """256 for n, m in [(3, 5), (5, 3), (4, 5), (5, 4)]:257 g=grid_graph([n,m])258 assert_equal(number_of_nodes(g), n*m)259 assert_equal(degree_histogram(g), [0,0,4,2*(n+m)-8,(n-2)*(m-2)])260 261 for n, m in [(1, 5), (5, 1)]:262 g=grid_graph([n,m])263 assert_equal(number_of_nodes(g), n*m)264 assert_true(is_isomorphic(g,path_graph(5)))265266# mg=grid_graph([n,m], create_using=MultiGraph())267# assert_equal(mg.edges(), g.edges())268269 def test_hypercube_graph(self):270 for n, G in [(0, null_graph()), (1, path_graph(2)),271 (2, cycle_graph(4)), (3, cubical_graph())]:272 g=hypercube_graph(n)273 assert_true(is_isomorphic(g, G))274275 g=hypercube_graph(4)276 assert_equal(degree_histogram(g), [0, 0, 0, 0, 16])277 g=hypercube_graph(5)278 assert_equal(degree_histogram(g), [0, 0, 0, 0, 0, 32])279 g=hypercube_graph(6)280 assert_equal(degree_histogram(g), [0, 0, 0, 0, 0, 0, 64])281 282# mg=hypercube_graph(6, create_using=MultiGraph())283# assert_equal(mg.edges(), g.edges())284285 def test_ladder_graph(self):286 for i, G in [(0, empty_graph(0)), (1, path_graph(2)),287 (2, hypercube_graph(2)), (10, grid_graph([2,10]))]:288 assert_true(is_isomorphic(ladder_graph(i), G))289290 assert_raises(networkx.exception.NetworkXError,291 ladder_graph, 2, create_using=DiGraph())292 293 g = ladder_graph(2)294 mg=ladder_graph(2, create_using=MultiGraph())295 assert_equal(mg.edges(), g.edges())296297 def test_lollipop_graph(self):298 # number of nodes = m1 + m2299 # number of edges = number_of_edges(complete_graph(m1)) + m2300 for m1, m2 in [(3, 5), (4, 10), (3, 20)]:301 b=lollipop_graph(m1,m2)302 assert_equal(number_of_nodes(b), m1+m2)303 assert_equal(number_of_edges(b), m1*(m1-1)/2 + m2)304 assert_equal(b.name,305 'lollipop_graph(' + str(m1) + ',' + str(m2) + ')')306307 # Raise NetworkXError if m<2308 assert_raises(networkx.exception.NetworkXError,309 lollipop_graph, 1, 20)310311 # Raise NetworkXError if n<0312 assert_raises(networkx.exception.NetworkXError,313 lollipop_graph, 5, -2)314315 # lollipop_graph(2,m) = path_graph(m+2)316 for m1, m2 in [(2, 5), (2, 10), (2, 20)]:317 b=lollipop_graph(m1,m2)318 assert_true(is_isomorphic(b, path_graph(m2+2)))319320 assert_raises(networkx.exception.NetworkXError,321 lollipop_graph, m1, m2, create_using=DiGraph())322 323 mb=lollipop_graph(m1, m2, create_using=MultiGraph())324 assert_true(mb.edges(), b.edges())325326 def test_null_graph(self):327 assert_equal(number_of_nodes(null_graph()), 0)328329 def test_path_graph(self):330 p=path_graph(0)331 assert_true(is_isomorphic(p, null_graph()))332 assert_equal(p.name, 'path_graph(0)')333334 p=path_graph(1)335 assert_true(is_isomorphic( p, empty_graph(1)))336 assert_equal(p.name, 'path_graph(1)')337338 p=path_graph(10)339 assert_true(is_connected(p))340 assert_equal(sorted(list(p.degree().values())),341 [1, 1, 2, 2, 2, 2, 2, 2, 2, 2])342 assert_equal(p.order()-1, p.size())343344 dp=path_graph(3, create_using=DiGraph())345 assert_true(dp.has_edge(0,1))346 assert_false(dp.has_edge(1,0))347 348 mp=path_graph(10, create_using=MultiGraph())349 assert_true(mp.edges()==p.edges())350351 def test_periodic_grid_2d_graph(self):352 g=grid_2d_graph(0,0, periodic=True)353 assert_equal(g.degree(), {})354355 for m, n, G in [(2, 2, cycle_graph(4)), (1, 7, cycle_graph(7)),356 (7, 1, cycle_graph(7)), (2, 5, circular_ladder_graph(5)),357 (5, 2, circular_ladder_graph(5)), (2, 4, cubical_graph()),358 (4, 2, cubical_graph())]:359 g=grid_2d_graph(m,n, periodic=True)360 assert_true(is_isomorphic(g, G))361362 DG=grid_2d_graph(4, 2, periodic=True, create_using=DiGraph())363 assert_equal(DG.succ,g.adj)364 assert_equal(DG.pred,g.adj)365 MG=grid_2d_graph(4, 2, periodic=True, create_using=MultiGraph())366 assert_equal(MG.edges(),g.edges())367368 def test_star_graph(self):369 assert_true(is_isomorphic(star_graph(0), empty_graph(1)))370 assert_true(is_isomorphic(star_graph(1), path_graph(2)))371 assert_true(is_isomorphic(star_graph(2), path_graph(3)))372 373 s=star_graph(10)374 assert_equal(sorted(list(s.degree().values())),375 [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 10])376 377 assert_raises(networkx.exception.NetworkXError,378 star_graph, 10, create_using=DiGraph())379 380 ms=star_graph(10, create_using=MultiGraph())381 assert_true(ms.edges()==s.edges())382383 def test_trivial_graph(self):384 assert_equal(number_of_nodes(trivial_graph()), 1)385386 def test_wheel_graph(self):387 for n, G in [(0, null_graph()), (1, empty_graph(1)),388 (2, path_graph(2)), (3, complete_graph(3)),389 (4, complete_graph(4))]:390 g=wheel_graph(n)391 assert_true(is_isomorphic( g, G))392 393 assert_equal(g.name, 'wheel_graph(4)')394395 g=wheel_graph(10)396 assert_equal(sorted(list(g.degree().values())),397 [3, 3, 3, 3, 3, 3, 3, 3, 3, 9])398 399 assert_raises(networkx.exception.NetworkXError,400 wheel_graph, 10, create_using=DiGraph())401 402 mg=wheel_graph(10, create_using=MultiGraph())403 assert_equal(mg.edges(), g.edges()) ...

Full Screen

Full Screen

test_product.py

Source:test_product.py Github

copy

Full Screen

...14 P3=nx.path_graph(3)15 P10=nx.path_graph(10)16 # null graph17 G=tensor_product(null,null)18 assert_true(nx.is_isomorphic(G,null))19 # null_graph X anything = null_graph and v.v.20 G=tensor_product(null,empty10)21 assert_true(nx.is_isomorphic(G,null))22 G=tensor_product(null,K3)23 assert_true(nx.is_isomorphic(G,null))24 G=tensor_product(null,K10)25 assert_true(nx.is_isomorphic(G,null))26 G=tensor_product(null,P3)27 assert_true(nx.is_isomorphic(G,null))28 G=tensor_product(null,P10)29 assert_true(nx.is_isomorphic(G,null))30 G=tensor_product(empty10,null)31 assert_true(nx.is_isomorphic(G,null))32 G=tensor_product(K3,null)33 assert_true(nx.is_isomorphic(G,null))34 G=tensor_product(K10,null)35 assert_true(nx.is_isomorphic(G,null))36 G=tensor_product(P3,null)37 assert_true(nx.is_isomorphic(G,null))38 G=tensor_product(P10,null)39 assert_true(nx.is_isomorphic(G,null))4041def test_tensor_product_size():42 P5 = nx.path_graph(5)43 K3 = nx.complete_graph(3)44 K5 = nx.complete_graph(5)45 46 G=tensor_product(P5,K3)47 assert_equal(nx.number_of_nodes(G),5*3)48 G=tensor_product(K3,K5)49 assert_equal(nx.number_of_nodes(G),3*5)505152def test_tensor_product_combinations():53 # basic smoke test, more realistic tests would be usefule54 P5 = nx.path_graph(5)55 K3 = nx.complete_graph(3)56 G=tensor_product(P5,K3)57 assert_equal(nx.number_of_nodes(G),5*3)58 G=tensor_product(P5,nx.MultiGraph(K3))59 assert_equal(nx.number_of_nodes(G),5*3)60 G=tensor_product(nx.MultiGraph(P5),K3)61 assert_equal(nx.number_of_nodes(G),5*3)62 G=tensor_product(nx.MultiGraph(P5),nx.MultiGraph(K3))63 assert_equal(nx.number_of_nodes(G),5*3)6465 G=tensor_product(nx.DiGraph(P5),nx.DiGraph(K3))66 assert_equal(nx.number_of_nodes(G),5*3)676869def test_tensor_product_classic_result():70 K2 = nx.complete_graph(2)71 G = nx.petersen_graph()72 G = tensor_product(G,K2)73 assert_true(nx.is_isomorphic(G,nx.desargues_graph()))7475 G = nx.cycle_graph(5)76 G = tensor_product(G,K2)77 assert_true(nx.is_isomorphic(G,nx.cycle_graph(10)))7879 G = nx.tetrahedral_graph()80 G = tensor_product(G,K2)81 assert_true(nx.is_isomorphic(G,nx.cubical_graph()))8283def test_tensor_product_random():84 G = nx.erdos_renyi_graph(10,2/10.)85 H = nx.erdos_renyi_graph(10,2/10.)86 GH = tensor_product(G,H)8788 for (u_G,u_H) in GH.nodes_iter():89 for (v_G,v_H) in GH.nodes_iter():90 if H.has_edge(u_H,v_H) and G.has_edge(u_G,v_G):91 assert_true(GH.has_edge((u_G,u_H),(v_G,v_H)))92 else:93 assert_true(not GH.has_edge((u_G,u_H),(v_G,v_H)))949596def test_cartesian_product_multigraph():97 G=nx.MultiGraph()98 G.add_edge(1,2,key=0)99 G.add_edge(1,2,key=1)100 H=nx.MultiGraph()101 H.add_edge(3,4,key=0)102 H.add_edge(3,4,key=1)103 GH=cartesian_product(G,H)104 assert_equal( set(GH) , set([(1, 3), (2, 3), (2, 4), (1, 4)]))105 assert_equal( set(GH.edges(keys=True)) ,106 set([((1, 3), (2, 3), 0), ((1, 3), (2, 3), 1), 107 ((1, 3), (1, 4), 0), ((1, 3), (1, 4), 1), 108 ((2, 3), (2, 4), 0), ((2, 3), (2, 4), 1), 109 ((2, 4), (1, 4), 0), ((2, 4), (1, 4), 1)])) 110111@raises(nx.NetworkXError)112def test_cartesian_product_raises():113 P = cartesian_product(nx.DiGraph(),nx.Graph())114115def test_cartesian_product_null():116 null=nx.null_graph()117 empty10=nx.empty_graph(10)118 K3=nx.complete_graph(3)119 K10=nx.complete_graph(10)120 P3=nx.path_graph(3)121 P10=nx.path_graph(10)122 # null graph123 G=cartesian_product(null,null)124 assert_true(nx.is_isomorphic(G,null))125 # null_graph X anything = null_graph and v.v.126 G=cartesian_product(null,empty10)127 assert_true(nx.is_isomorphic(G,null))128 G=cartesian_product(null,K3)129 assert_true(nx.is_isomorphic(G,null))130 G=cartesian_product(null,K10)131 assert_true(nx.is_isomorphic(G,null))132 G=cartesian_product(null,P3)133 assert_true(nx.is_isomorphic(G,null))134 G=cartesian_product(null,P10)135 assert_true(nx.is_isomorphic(G,null))136 G=cartesian_product(empty10,null)137 assert_true(nx.is_isomorphic(G,null))138 G=cartesian_product(K3,null)139 assert_true(nx.is_isomorphic(G,null))140 G=cartesian_product(K10,null)141 assert_true(nx.is_isomorphic(G,null))142 G=cartesian_product(P3,null)143 assert_true(nx.is_isomorphic(G,null))144 G=cartesian_product(P10,null)145 assert_true(nx.is_isomorphic(G,null))146147def test_cartesian_product_size():148 # order(GXH)=order(G)*order(H)149 K5=nx.complete_graph(5)150 P5=nx.path_graph(5)151 K3=nx.complete_graph(3)152 G=cartesian_product(P5,K3)153 assert_equal(nx.number_of_nodes(G),5*3)154 assert_equal(nx.number_of_edges(G),155 nx.number_of_edges(P5)*nx.number_of_nodes(K3)+156 nx.number_of_edges(K3)*nx.number_of_nodes(P5))157 G=cartesian_product(K3,K5)158 assert_equal(nx.number_of_nodes(G),3*5)159 assert_equal(nx.number_of_edges(G),160 nx.number_of_edges(K5)*nx.number_of_nodes(K3)+161 nx.number_of_edges(K3)*nx.number_of_nodes(K5))162163def test_cartesian_product_classic():164 # test some classic product graphs165 P2 = nx.path_graph(2)166 P3 = nx.path_graph(3)167 # cube = 2-path X 2-path168 G=cartesian_product(P2,P2)169 G=cartesian_product(P2,G)170 assert_true(nx.is_isomorphic(G,nx.cubical_graph()))171172 # 3x3 grid173 G=cartesian_product(P3,P3)174 assert_true(nx.is_isomorphic(G,nx.grid_2d_graph(3,3)))175176def test_cartesian_product_random():177 G = nx.erdos_renyi_graph(10,2/10.)178 H = nx.erdos_renyi_graph(10,2/10.)179 GH = cartesian_product(G,H)180181 for (u_G,u_H) in GH.nodes_iter():182 for (v_G,v_H) in GH.nodes_iter():183 if (u_G==v_G and H.has_edge(u_H,v_H)) or \184 (u_H==v_H and G.has_edge(u_G,v_G)):185 assert_true(GH.has_edge((u_G,u_H),(v_G,v_H)))186 else:187 assert_true(not GH.has_edge((u_G,u_H),(v_G,v_H)))188189@raises(nx.NetworkXError)190def test_lexicographic_product_raises():191 P=lexicographic_product(nx.DiGraph(),nx.Graph())192193def test_lexicographic_product_null():194 null=nx.null_graph()195 empty10=nx.empty_graph(10)196 K3=nx.complete_graph(3)197 K10=nx.complete_graph(10)198 P3=nx.path_graph(3)199 P10=nx.path_graph(10)200 # null graph201 G=lexicographic_product(null,null)202 assert_true(nx.is_isomorphic(G,null))203 # null_graph X anything = null_graph and v.v.204 G=lexicographic_product(null,empty10)205 assert_true(nx.is_isomorphic(G,null))206 G=lexicographic_product(null,K3)207 assert_true(nx.is_isomorphic(G,null))208 G=lexicographic_product(null,K10)209 assert_true(nx.is_isomorphic(G,null))210 G=lexicographic_product(null,P3)211 assert_true(nx.is_isomorphic(G,null))212 G=lexicographic_product(null,P10)213 assert_true(nx.is_isomorphic(G,null))214 G=lexicographic_product(empty10,null)215 assert_true(nx.is_isomorphic(G,null))216 G=lexicographic_product(K3,null)217 assert_true(nx.is_isomorphic(G,null))218 G=lexicographic_product(K10,null)219 assert_true(nx.is_isomorphic(G,null))220 G=lexicographic_product(P3,null)221 assert_true(nx.is_isomorphic(G,null))222 G=lexicographic_product(P10,null)223 assert_true(nx.is_isomorphic(G,null))224225def test_lexicographic_product_size():226 K5=nx.complete_graph(5)227 P5=nx.path_graph(5)228 K3=nx.complete_graph(3)229 G=lexicographic_product(P5,K3)230 assert_equal(nx.number_of_nodes(G),5*3)231 G=lexicographic_product(K3,K5)232 assert_equal(nx.number_of_nodes(G),3*5)233234def test_lexicographic_product_combinations():235 P5=nx.path_graph(5)236 K3=nx.complete_graph(3)237 G=lexicographic_product(P5,K3)238 assert_equal(nx.number_of_nodes(G),5*3)239 G=lexicographic_product(nx.MultiGraph(P5),K3)240 assert_equal(nx.number_of_nodes(G),5*3)241 G=lexicographic_product(P5,nx.MultiGraph(K3))242 assert_equal(nx.number_of_nodes(G),5*3)243 G=lexicographic_product(nx.MultiGraph(P5),nx.MultiGraph(K3))244 assert_equal(nx.number_of_nodes(G),5*3)245246247248249 #No classic easily found classic results for lexicographic product250def test_lexicographic_product_random():251 G = nx.erdos_renyi_graph(10,2/10.)252 H = nx.erdos_renyi_graph(10,2/10.)253 GH = lexicographic_product(G,H)254255 for (u_G,u_H) in GH.nodes_iter():256 for (v_G,v_H) in GH.nodes_iter():257 if G.has_edge(u_G,v_G) or (u_G==v_G and H.has_edge(u_H,v_H)):258 assert_true(GH.has_edge((u_G,u_H),(v_G,v_H)))259 else:260 assert_true(not GH.has_edge((u_G,u_H),(v_G,v_H)))261262@raises(nx.NetworkXError)263def test_strong_product_raises():264 P = strong_product(nx.DiGraph(),nx.Graph())265266def test_strong_product_null():267 null=nx.null_graph()268 empty10=nx.empty_graph(10)269 K3=nx.complete_graph(3)270 K10=nx.complete_graph(10)271 P3=nx.path_graph(3)272 P10=nx.path_graph(10)273 # null graph274 G=strong_product(null,null)275 assert_true(nx.is_isomorphic(G,null))276 # null_graph X anything = null_graph and v.v.277 G=strong_product(null,empty10)278 assert_true(nx.is_isomorphic(G,null))279 G=strong_product(null,K3)280 assert_true(nx.is_isomorphic(G,null))281 G=strong_product(null,K10)282 assert_true(nx.is_isomorphic(G,null))283 G=strong_product(null,P3)284 assert_true(nx.is_isomorphic(G,null))285 G=strong_product(null,P10)286 assert_true(nx.is_isomorphic(G,null))287 G=strong_product(empty10,null)288 assert_true(nx.is_isomorphic(G,null))289 G=strong_product(K3,null)290 assert_true(nx.is_isomorphic(G,null))291 G=strong_product(K10,null)292 assert_true(nx.is_isomorphic(G,null))293 G=strong_product(P3,null)294 assert_true(nx.is_isomorphic(G,null))295 G=strong_product(P10,null)296 assert_true(nx.is_isomorphic(G,null))297298def test_strong_product_size():299 K5=nx.complete_graph(5)300 P5=nx.path_graph(5)301 K3 = nx.complete_graph(3)302 G=strong_product(P5,K3)303 assert_equal(nx.number_of_nodes(G),5*3)304 G=strong_product(K3,K5)305 assert_equal(nx.number_of_nodes(G),3*5)306307def test_strong_product_combinations():308 P5=nx.path_graph(5)309 K3 = nx.complete_graph(3)310 G=strong_product(P5,K3)311 assert_equal(nx.number_of_nodes(G),5*3)312 G=strong_product(nx.MultiGraph(P5),K3)313 assert_equal(nx.number_of_nodes(G),5*3)314 G=strong_product(P5,nx.MultiGraph(K3))315 assert_equal(nx.number_of_nodes(G),5*3)316 G=strong_product(nx.MultiGraph(P5),nx.MultiGraph(K3))317 assert_equal(nx.number_of_nodes(G),5*3)318319320321 #No classic easily found classic results for strong product322def test_strong_product_random():323 G = nx.erdos_renyi_graph(10,2/10.)324 H = nx.erdos_renyi_graph(10,2/10.)325 GH = strong_product(G,H)326327 for (u_G,u_H) in GH.nodes_iter():328 for (v_G,v_H) in GH.nodes_iter():329 if (u_G==v_G and H.has_edge(u_H,v_H)) or \330 (u_H==v_H and G.has_edge(u_G,v_G)) or \331 (G.has_edge(u_G,v_G) and H.has_edge(u_H,v_H)):332 assert_true(GH.has_edge((u_G,u_H),(v_G,v_H)))333 else: ...

Full Screen

Full Screen

test_misc.py

Source:test_misc.py Github

copy

Full Screen

...3from nose import SkipTest4import networkx as nx5from networkx.utils import *6def test_is_string_like():7 assert_true(is_string_like("aaaa"))8 assert_false(is_string_like(None))9 assert_false(is_string_like(123))10def test_iterable():11 assert_false(iterable(None))12 assert_false(iterable(10))13 assert_true(iterable([1, 2, 3]))14 assert_true(iterable((1, 2, 3)))15 assert_true(iterable({1: "A", 2: "X"}))16 assert_true(iterable("ABC"))17def test_graph_iterable():18 K = nx.complete_graph(10)19 assert_true(iterable(K))20 assert_true(iterable(K.nodes()))21 assert_true(iterable(K.edges()))22def test_is_list_of_ints():23 assert_true(is_list_of_ints([1, 2, 3, 42]))24 assert_false(is_list_of_ints([1, 2, 3, "kermit"]))25def test_random_number_distribution():26 # smoke test only27 z = powerlaw_sequence(20, exponent=2.5)28 z = discrete_sequence(20, distribution=[0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 3])29def test_make_str_with_bytes():30 import sys31 PY2 = sys.version_info[0] == 232 x = "qualité"33 y = make_str(x)34 if PY2:35 assert_true(isinstance(y, unicode))36 # Since file encoding is utf-8, the é will be two bytes.37 assert_true(len(y) == 8)38 else:39 assert_true(isinstance(y, str))40 assert_true(len(y) == 7)41def test_make_str_with_unicode():42 import sys43 PY2 = sys.version_info[0] == 244 if PY2:45 x = unicode("qualité", encoding='utf-8')46 y = make_str(x)47 assert_true(isinstance(y, unicode))48 assert_true(len(y) == 7)49 else:50 x = "qualité"51 y = make_str(x)52 assert_true(isinstance(y, str))53 assert_true(len(y) == 7)54class TestNumpyArray(object):55 @classmethod56 def setupClass(cls):57 global numpy58 global assert_allclose59 try:60 import numpy61 from numpy.testing import assert_allclose62 except ImportError:63 raise SkipTest('NumPy not available.')64 def test_dict_to_numpy_array1(self):65 d = {'a': 1, 'b': 2}66 a = dict_to_numpy_array1(d, mapping={'a': 0, 'b': 1})67 assert_allclose(a, numpy.array([1, 2]))68 a = dict_to_numpy_array1(d, mapping={'b': 0, 'a': 1})69 assert_allclose(a, numpy.array([2, 1]))70 a = dict_to_numpy_array1(d)71 assert_allclose(a.sum(), 3)72 def test_dict_to_numpy_array2(self):73 d = {'a': {'a': 1, 'b': 2},74 'b': {'a': 10, 'b': 20}}75 mapping = {'a': 1, 'b': 0}76 a = dict_to_numpy_array2(d, mapping=mapping)77 assert_allclose(a, numpy.array([[20, 10], [2, 1]]))78 a = dict_to_numpy_array2(d)79 assert_allclose(a.sum(), 33)80 def test_dict_to_numpy_array_a(self):81 d = {'a': {'a': 1, 'b': 2},82 'b': {'a': 10, 'b': 20}}83 mapping = {'a': 0, 'b': 1}84 a = dict_to_numpy_array(d, mapping=mapping)85 assert_allclose(a, numpy.array([[1, 2], [10, 20]]))86 mapping = {'a': 1, 'b': 0}87 a = dict_to_numpy_array(d, mapping=mapping)88 assert_allclose(a, numpy.array([[20, 10], [2, 1]]))89 a = dict_to_numpy_array2(d)90 assert_allclose(a.sum(), 33)91 def test_dict_to_numpy_array_b(self):92 d = {'a': 1, 'b': 2}93 mapping = {'a': 0, 'b': 1}94 a = dict_to_numpy_array(d, mapping=mapping)95 assert_allclose(a, numpy.array([1, 2]))96 a = dict_to_numpy_array1(d)97 assert_allclose(a.sum(), 3)98def test_pairwise():99 nodes = range(4)100 node_pairs = [(0, 1), (1, 2), (2, 3)]101 node_pairs_cycle = node_pairs + [(3, 0)]102 assert_equal(list(pairwise(nodes)), node_pairs)103 assert_equal(list(pairwise(iter(nodes))), node_pairs)104 assert_equal(list(pairwise(nodes, cyclic=True)), node_pairs_cycle)105 empty_iter = iter(())106 assert_equal(list(pairwise(empty_iter)), [])107 empty_iter = iter(())108 assert_equal(list(pairwise(empty_iter, cyclic=True)), [])109def test_groups():110 many_to_one = dict(zip('abcde', [0, 0, 1, 1, 2]))111 actual = groups(many_to_one)112 expected = {0: {'a', 'b'}, 1: {'c', 'd'}, 2: {'e'}}113 assert_equal(actual, expected)114 assert_equal({}, groups({}))115def test_to_tuple():116 a_list = [1, 2, [1, 3]]117 actual = to_tuple(a_list)118 expected = (1, 2, (1, 3))119 assert_equal(actual, expected)120 a_tuple = (1, 2)121 actual = to_tuple(a_tuple)122 expected = a_tuple123 assert_equal(actual, expected)124 a_mix = (1, 2, [1, 3])125 actual = to_tuple(a_mix)126 expected = (1, 2, (1, 3))127 assert_equal(actual, expected)128def test_create_random_state():129 try:130 import numpy as np131 except ImportError:132 raise SkipTest('numpy not available.')133 rs = np.random.RandomState134 assert_true(isinstance(create_random_state(1), rs))135 assert_true(isinstance(create_random_state(None), rs))136 assert_true(isinstance(create_random_state(np.random), rs))137 assert_true(isinstance(create_random_state(rs(1)), rs))138 assert_raises(ValueError, create_random_state, 'a')139 assert_true(np.all((rs(1).rand(10) == create_random_state(1).rand(10))))140def test_create_py_random_state():141 pyrs = random.Random142 assert_true(isinstance(create_py_random_state(1), pyrs))143 assert_true(isinstance(create_py_random_state(None), pyrs))144 assert_true(isinstance(create_py_random_state(pyrs(1)), pyrs))145 assert_raises(ValueError, create_py_random_state, 'a')146 try:147 import numpy as np148 except ImportError:149 raise SkipTest('numpy not available.')150 rs = np.random.RandomState151 nprs = PythonRandomInterface152 assert_true(isinstance(create_py_random_state(np.random), nprs))153 assert_true(isinstance(create_py_random_state(rs(1)), nprs))154 # test default rng input155 assert_true(isinstance(PythonRandomInterface(), nprs))156def test_PythonRandomInterface():157 try:158 import numpy as np159 except ImportError:160 raise SkipTest('numpy not available.')161 rs = np.random.RandomState162 rng = PythonRandomInterface(rs(42))163 rs42 = rs(42)164 # make sure these functions are same as expected outcome165 assert_equal(rng.randrange(3, 5), rs42.randint(3, 5))166 assert_true(np.all(rng.choice([1, 2, 3]) == rs42.choice([1, 2, 3])))167 assert_equal(rng.gauss(0, 1), rs42.normal(0, 1))168 assert_equal(rng.expovariate(1.5), rs42.exponential(1/1.5))169 assert_true(np.all(rng.shuffle([1, 2, 3]) == rs42.shuffle([1, 2, 3])))170 assert_true(np.all(rng.sample([1, 2, 3], 2) ==171 rs42.choice([1, 2, 3], (2,), replace=False)))172 assert_equal(rng.randint(3, 5), rs42.randint(3, 6))...

Full Screen

Full Screen

test_filters.py

Source:test_filters.py Github

copy

Full Screen

2import networkx as nx3class TestFilterFactory(object):4 def test_no_filter(self):5 nf = nx.filters.no_filter6 assert_true(nf())7 assert_true(nf(1))8 assert_true(nf(2, 1))9 def test_hide_nodes(self):10 f = nx.classes.filters.hide_nodes([1, 2, 3])11 assert_false(f(1))12 assert_false(f(2))13 assert_false(f(3))14 assert_true(f(4))15 assert_true(f(0))16 assert_true(f('a'))17 assert_raises(TypeError, f, 1, 2)18 assert_raises(TypeError, f)19 def test_show_nodes(self):20 f = nx.classes.filters.show_nodes([1, 2, 3])21 assert_true(f(1))22 assert_true(f(2))23 assert_true(f(3))24 assert_false(f(4))25 assert_false(f(0))26 assert_false(f('a'))27 assert_raises(TypeError, f, 1, 2)28 assert_raises(TypeError, f)29 def test_hide_edges(self):30 factory = nx.classes.filters.hide_edges31 f = factory([(1, 2), (3, 4)])32 assert_false(f(1, 2))33 assert_false(f(3, 4))34 assert_false(f(4, 3))35 assert_true(f(2, 3))36 assert_true(f(0, -1))37 assert_true(f('a', 'b'))38 assert_raises(TypeError, f, 1, 2, 3)39 assert_raises(TypeError, f, 1)40 assert_raises(TypeError, f)41 assert_raises(TypeError, factory, [1, 2, 3])42 assert_raises(ValueError, factory, [(1, 2, 3)])43 def test_show_edges(self):44 factory = nx.classes.filters.show_edges45 f = factory([(1, 2), (3, 4)])46 assert_true(f(1, 2))47 assert_true(f(3, 4))48 assert_true(f(4, 3))49 assert_false(f(2, 3))50 assert_false(f(0, -1))51 assert_false(f('a', 'b'))52 assert_raises(TypeError, f, 1, 2, 3)53 assert_raises(TypeError, f, 1)54 assert_raises(TypeError, f)55 assert_raises(TypeError, factory, [1, 2, 3])56 assert_raises(ValueError, factory, [(1, 2, 3)])57 def test_hide_diedges(self):58 factory = nx.classes.filters.hide_diedges59 f = factory([(1, 2), (3, 4)])60 assert_false(f(1, 2))61 assert_false(f(3, 4))62 assert_true(f(4, 3))63 assert_true(f(2, 3))64 assert_true(f(0, -1))65 assert_true(f('a', 'b'))66 assert_raises(TypeError, f, 1, 2, 3)67 assert_raises(TypeError, f, 1)68 assert_raises(TypeError, f)69 assert_raises(TypeError, factory, [1, 2, 3])70 assert_raises(ValueError, factory, [(1, 2, 3)])71 def test_show_diedges(self):72 factory = nx.classes.filters.show_diedges73 f = factory([(1, 2), (3, 4)])74 assert_true(f(1, 2))75 assert_true(f(3, 4))76 assert_false(f(4, 3))77 assert_false(f(2, 3))78 assert_false(f(0, -1))79 assert_false(f('a', 'b'))80 assert_raises(TypeError, f, 1, 2, 3)81 assert_raises(TypeError, f, 1)82 assert_raises(TypeError, f)83 assert_raises(TypeError, factory, [1, 2, 3])84 assert_raises(ValueError, factory, [(1, 2, 3)])85 def test_hide_multiedges(self):86 factory = nx.classes.filters.hide_multiedges87 f = factory([(1, 2, 0), (3, 4, 1), (1, 2, 1)])88 assert_false(f(1, 2, 0))89 assert_false(f(1, 2, 1))90 assert_true(f(1, 2, 2))91 assert_true(f(3, 4, 0))92 assert_false(f(3, 4, 1))93 assert_false(f(4, 3, 1))94 assert_true(f(4, 3, 0))95 assert_true(f(2, 3, 0))96 assert_true(f(0, -1, 0))97 assert_true(f('a', 'b', 0))98 assert_raises(TypeError, f, 1, 2, 3, 4)99 assert_raises(TypeError, f, 1, 2)100 assert_raises(TypeError, f, 1)101 assert_raises(TypeError, f)102 assert_raises(TypeError, factory, [1, 2, 3])103 assert_raises(ValueError, factory, [(1, 2)])104 assert_raises(ValueError, factory, [(1, 2, 3, 4)])105 def test_show_multiedges(self):106 factory = nx.classes.filters.show_multiedges107 f = factory([(1, 2, 0), (3, 4, 1), (1, 2, 1)])108 assert_true(f(1, 2, 0))109 assert_true(f(1, 2, 1))110 assert_false(f(1, 2, 2))111 assert_false(f(3, 4, 0))112 assert_true(f(3, 4, 1))113 assert_true(f(4, 3, 1))114 assert_false(f(4, 3, 0))115 assert_false(f(2, 3, 0))116 assert_false(f(0, -1, 0))117 assert_false(f('a', 'b', 0))118 assert_raises(TypeError, f, 1, 2, 3, 4)119 assert_raises(TypeError, f, 1, 2)120 assert_raises(TypeError, f, 1)121 assert_raises(TypeError, f)122 assert_raises(TypeError, factory, [1, 2, 3])123 assert_raises(ValueError, factory, [(1, 2)])124 assert_raises(ValueError, factory, [(1, 2, 3, 4)])125 def test_hide_multidiedges(self):126 factory = nx.classes.filters.hide_multidiedges127 f = factory([(1, 2, 0), (3, 4, 1), (1, 2, 1)])128 assert_false(f(1, 2, 0))129 assert_false(f(1, 2, 1))130 assert_true(f(1, 2, 2))131 assert_true(f(3, 4, 0))132 assert_false(f(3, 4, 1))133 assert_true(f(4, 3, 1))134 assert_true(f(4, 3, 0))135 assert_true(f(2, 3, 0))136 assert_true(f(0, -1, 0))137 assert_true(f('a', 'b', 0))138 assert_raises(TypeError, f, 1, 2, 3, 4)139 assert_raises(TypeError, f, 1, 2)140 assert_raises(TypeError, f, 1)141 assert_raises(TypeError, f)142 assert_raises(TypeError, factory, [1, 2, 3])143 assert_raises(ValueError, factory, [(1, 2)])144 assert_raises(ValueError, factory, [(1, 2, 3, 4)])145 def test_show_multidiedges(self):146 factory = nx.classes.filters.show_multidiedges147 f = factory([(1, 2, 0), (3, 4, 1), (1, 2, 1)])148 assert_true(f(1, 2, 0))149 assert_true(f(1, 2, 1))150 assert_false(f(1, 2, 2))151 assert_false(f(3, 4, 0))152 assert_true(f(3, 4, 1))153 assert_false(f(4, 3, 1))154 assert_false(f(4, 3, 0))155 assert_false(f(2, 3, 0))156 assert_false(f(0, -1, 0))157 assert_false(f('a', 'b', 0))158 assert_raises(TypeError, f, 1, 2, 3, 4)159 assert_raises(TypeError, f, 1, 2)160 assert_raises(TypeError, f, 1)161 assert_raises(TypeError, f)162 assert_raises(TypeError, factory, [1, 2, 3])163 assert_raises(ValueError, factory, [(1, 2)])...

Full Screen

Full Screen

test_graphical.py

Source:test_graphical.py Github

copy

Full Screen

...7 p = .38 for i in range(10):9 G = nx.erdos_renyi_graph(n, p)10 deg = (d for n, d in G.degree())11 assert_true(nx.is_graphical(deg, method='eg'))12 assert_true(nx.is_graphical(deg, method='hh'))13def test_valid_degree_sequence2():14 n = 10015 for i in range(10):16 G = nx.barabasi_albert_graph(n, 1)17 deg = (d for n, d in G.degree())18 assert_true(nx.is_graphical(deg, method='eg'))19 assert_true(nx.is_graphical(deg, method='hh'))20@raises(nx.NetworkXException)21def test_string_input():22 a = nx.is_graphical([], 'foo')23def test_negative_input():24 assert_false(nx.is_graphical([-1], 'hh'))25 assert_false(nx.is_graphical([-1], 'eg'))26@raises(nx.NetworkXException)27def test_non_integer_input():28 a = nx.is_graphical([72.5], 'eg')29@raises(nx.NetworkXException)30def test_non_integer_input():31 a = nx.is_graphical([72.5], 'hh')32class TestAtlas(object):33 @classmethod34 def setupClass(cls):35 global atlas36 import platform37 if platform.python_implementation() == 'Jython':38 raise SkipTest('graph atlas not available under Jython.')39 import networkx.generators.atlas as atlas40 def setUp(self):41 self.GAG = atlas.graph_atlas_g()42 def test_atlas(self):43 for graph in self.GAG:44 deg = (d for n, d in graph.degree())45 assert_true(nx.is_graphical(deg, method='eg'))46 assert_true(nx.is_graphical(deg, method='hh'))47def test_small_graph_true():48 z = [5, 3, 3, 3, 3, 2, 2, 2, 1, 1, 1]49 assert_true(nx.is_graphical(z, method='hh'))50 assert_true(nx.is_graphical(z, method='eg'))51 z = [10, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2]52 assert_true(nx.is_graphical(z, method='hh'))53 assert_true(nx.is_graphical(z, method='eg'))54 z = [1, 1, 1, 1, 1, 2, 2, 2, 3, 4]55 assert_true(nx.is_graphical(z, method='hh'))56 assert_true(nx.is_graphical(z, method='eg'))57def test_small_graph_false():58 z = [1000, 3, 3, 3, 3, 2, 2, 2, 1, 1, 1]59 assert_false(nx.is_graphical(z, method='hh'))60 assert_false(nx.is_graphical(z, method='eg'))61 z = [6, 5, 4, 4, 2, 1, 1, 1]62 assert_false(nx.is_graphical(z, method='hh'))63 assert_false(nx.is_graphical(z, method='eg'))64 z = [1, 1, 1, 1, 1, 1, 2, 2, 2, 3, 4]65 assert_false(nx.is_graphical(z, method='hh'))66 assert_false(nx.is_graphical(z, method='eg'))67def test_directed_degree_sequence():68 # Test a range of valid directed degree sequences69 n, r = 100, 1070 p = 1.0 / r71 for i in range(r):72 G = nx.erdos_renyi_graph(n, p * (i + 1), None, True)73 din = (d for n, d in G.in_degree())74 dout = (d for n, d in G.out_degree())75 assert_true(nx.is_digraphical(din, dout))76def test_small_directed_sequences():77 dout = [5, 3, 3, 3, 3, 2, 2, 2, 1, 1, 1]78 din = [3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 1]79 assert_true(nx.is_digraphical(din, dout))80 # Test nongraphical directed sequence81 dout = [1000, 3, 3, 3, 3, 2, 2, 2, 1, 1, 1]82 din = [103, 102, 102, 102, 102, 102, 102, 102, 102, 102]83 assert_false(nx.is_digraphical(din, dout))84 # Test digraphical small sequence85 dout = [1, 1, 1, 1, 1, 2, 2, 2, 3, 4]86 din = [2, 2, 2, 2, 2, 2, 2, 2, 1, 1]87 assert_true(nx.is_digraphical(din, dout))88 # Test nonmatching sum89 din = [2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1]90 assert_false(nx.is_digraphical(din, dout))91 # Test for negative integer in sequence92 din = [2, 2, 2, -2, 2, 2, 2, 2, 1, 1, 4]93 assert_false(nx.is_digraphical(din, dout))94def test_multi_sequence():95 # Test nongraphical multi sequence96 seq = [1000, 3, 3, 3, 3, 2, 2, 2, 1, 1]97 assert_false(nx.is_multigraphical(seq))98 # Test small graphical multi sequence99 seq = [6, 5, 4, 4, 2, 1, 1, 1]100 assert_true(nx.is_multigraphical(seq))101 # Test for negative integer in sequence102 seq = [6, 5, 4, -4, 2, 1, 1, 1]103 assert_false(nx.is_multigraphical(seq))104 # Test for sequence with odd sum105 seq = [1, 1, 1, 1, 1, 1, 2, 2, 2, 3, 4]106 assert_false(nx.is_multigraphical(seq))107def test_pseudo_sequence():108 # Test small valid pseudo sequence109 seq = [1000, 3, 3, 3, 3, 2, 2, 2, 1, 1]110 assert_true(nx.is_pseudographical(seq))111 # Test for sequence with odd sum112 seq = [1000, 3, 3, 3, 3, 2, 2, 2, 1, 1, 1]113 assert_false(nx.is_pseudographical(seq))114 # Test for negative integer in sequence115 seq = [1000, 3, 3, 3, 3, 2, 2, -2, 1, 1]116 assert_false(nx.is_pseudographical(seq))117def test_numpy_degree_sequence():118 try:119 import numpy120 except ImportError:121 return122 ds = numpy.array([1, 2, 2, 2, 1], dtype=numpy.int64)123 assert_true(nx.is_graphical(ds, 'eg'))124 assert_true(nx.is_graphical(ds, 'hh'))125 ds = numpy.array([1, 2, 2, 2, 1], dtype=numpy.float64)126 assert_true(nx.is_graphical(ds, 'eg'))127 assert_true(nx.is_graphical(ds, 'hh'))128@raises(nx.NetworkXError, AssertionError)129def test_numpy_noninteger_degree_sequence():130 try:131 import numpy132 except ImportError:133 raise nx.NetworkXError('make test pass by raising exception')134 ds = numpy.array([1.1, 2, 2, 2, 1], dtype=numpy.float64)...

Full Screen

Full Screen

test_feature_agglomeration.py

Source:test_feature_agglomeration.py Github

copy

Full Screen

...14 agglo_median = FeatureAgglomeration(n_clusters=n_clusters,15 pooling_func=np.median)16 agglo_mean.fit(X)17 agglo_median.fit(X)18 assert_true(np.size(np.unique(agglo_mean.labels_)) == n_clusters)19 assert_true(np.size(np.unique(agglo_median.labels_)) == n_clusters)20 assert_true(np.size(agglo_mean.labels_) == X.shape[1])21 assert_true(np.size(agglo_median.labels_) == X.shape[1])22 # Test transform23 Xt_mean = agglo_mean.transform(X)24 Xt_median = agglo_median.transform(X)25 assert_true(Xt_mean.shape[1] == n_clusters)26 assert_true(Xt_median.shape[1] == n_clusters)27 assert_true(Xt_mean == np.array([1 / 3.]))28 assert_true(Xt_median == np.array([0.]))29 # Test inverse transform30 X_full_mean = agglo_mean.inverse_transform(Xt_mean)31 X_full_median = agglo_median.inverse_transform(Xt_median)32 assert_true(np.unique(X_full_mean[0]).size == n_clusters)33 assert_true(np.unique(X_full_median[0]).size == n_clusters)34 assert_array_almost_equal(agglo_mean.transform(X_full_mean),35 Xt_mean)36 assert_array_almost_equal(agglo_median.transform(X_full_median),...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1function assert_true(condition, message) {2 if (!condition) {3 throw new Error(message);4 }5}6function assert_equals(a, b, message) {7 if (a !== b) {8 throw new Error(message);9 }10}11function assert_throws(exception, func, message) {12 try {13 func();14 throw new Error(message);15 } catch (e) {16 if (e.constructor !== exception) {17 throw new Error(message);18 }19 }20}21function assert_object_equals(a, b, message) {22 if (JSON.stringify(a) !== JSON.stringify(b)) {23 throw new Error(message);24 }25}26function assert_array_equals(a, b, message) {27 if (a.length !== b.length) {28 throw new Error(message);29 }30 for (var i = 0; i < a.length; i++) {31 if (a[i] !== b[i]) {32 throw new Error(message);33 }34 }35}36function assert_unreached(message) {37 throw new Error(message);38}39function promise_rejects(t, exception, promise, message) {40 return promise.then(function() {41 throw new Error(message);42 }, function(e) {43 if (e.constructor !== exception) {44 throw new Error(message);45 }46 });47}48function promise_rejects_dom(t, name, promise, message) {49 return promise_rejects(t, DOMException, promise, message);50}51function promise_rejects_exactly(t, exception, promise, message) {52 return promise.then(function() {53 throw new Error(message);54 }, function(e) {55 if (e !== exception) {56 throw new Error(message);57 }58 });59}60function promise_rejects_js(t, exception, promise, message) {61 return promise.then(function() {62 throw new Error(message);

Full Screen

Using AI Code Generation

copy

Full Screen

1assert_true(true, "This assertion should pass");2assert_true(false, "This assertion should fail");3assert_equals(1, 1, "This assertion should pass");4assert_equals(1, 2, "This assertion should fail");5assert_array_equals([1,2,3], [1,2,3], "This assertion should pass");6assert_array_equals([1,2,3], [1,2,4], "This assertion should fail");7assert_object_equals({a:1, b:2}, {a:1, b:2}, "This assertion should pass");8assert_object_equals({a:1, b:2}, {a:1, b:3}, "This assertion should fail");9assert_throws(new TypeError(), () => { throw new TypeError(); }, "This assertion should pass");10assert_throws(new TypeError(), () => { throw new ReferenceError(); }, "This assertion should fail");11assert_unreached("This assertion should fail");12promise_rejects(new TypeError(), Promise.reject(new TypeError()), "This assertion should pass");13promise_rejects(new TypeError(), Promise.reject(new ReferenceError()), "This assertion should fail");14promise_rejects_dom(t, 'InvalidStateError', Promise.reject(new TypeError()), "This assertion should pass");15promise_rejects_dom(t, 'InvalidStateError', Promise.reject(new ReferenceError()), "This assertion should fail");16promise_rejects_js(t, TypeError, Promise.reject(new TypeError()), "This assertion should pass");17promise_rejects_js(t, TypeError, Promise.reject(new ReferenceError()), "This assertion should fail");18promise_rejects_unreached(t, Promise.reject(new TypeError()), "This assertion should fail");19promise_rejects_exactly(t, new TypeError(), Promise.reject(new TypeError()), "This assertion should pass");

Full Screen

Using AI Code Generation

copy

Full Screen

1assert_true(1 === 1, "1 is equal to 1");2assert_true(1 === 2, "1 is equal to 2");3assert_true(1 === 3, "1 is equal to 3");4assert_true(1 === 4, "1 is equal to 4");5assert_true(1 === 5, "1 is equal to 5");6assert_true(1 === 6, "1 is equal to 6");7assert_true(1 === 7, "1 is equal to 7");8assert_true(1 === 8, "1 is equal to 8");9assert_true(1 === 9, "1 is equal to 9");10assert_true(1 === 10, "1 is equal to 10");11assert_true(1 === 11, "1 is equal to 11");12assert_true(1 === 12, "1 is equal to 12");13assert_true(1 === 13, "1 is equal to 13");14assert_true(1 === 14, "1 is equal to 14");15assert_true(1 === 15, "1 is equal to 15");16assert_true(1 === 16, "1 is equal to 16");17assert_true(1 === 17, "1 is equal to 17");18assert_true(1 === 18, "1 is equal to 18");19assert_true(1 === 19, "1 is equal to 19");20assert_true(1 === 20, "1 is equal to 20");21assert_true(1 === 21, "1 is equal to 21");22assert_true(1 === 22, "1 is equal to 22");23assert_true(1 === 23, "1 is equal to 23");24assert_true(1 === 24, "1 is equal to 24");25assert_true(1 === 25, "1 is equal to 25");26assert_true(1 === 26, "1 is equal to 26");27assert_true(1 === 27, "1 is equal to 27");28assert_true(1 === 28, "1 is equal to 28");29assert_true(1 === 29, "1 is equal to 29");30assert_true(1 === 30, "1 is equal to 30");31assert_true(1 === 31, "1 is equal to 31");

Full Screen

Using AI Code Generation

copy

Full Screen

1assert_true(true, 'true is true');2function assert_true(actual, description) {3 if (actual !== true) {4 throw new TestFailed('assert_true failed: ' + description);5 }6}7function TestFailed(message) {8 this.message = message;9}10TestFailed.prototype.toString = function() {11 return 'TestFailed: ' + this.message;12};13assert_true(true, 'true is true');

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('wpt-api');2var assert = require('assert');3var test = new wpt('your api key');4test.getTestResults('140314_6Q_1', function(err, data) {5 assert.ifError(err);6 assert.ok(data);7 assert.ok(data.data);8 assert.ok(data.data.runs);9 assert.ok(data.data.runs[1]);10});

Full Screen

Using AI Code Generation

copy

Full Screen

1function test() {2 assert_true(true, "true is true");3 assert_true(false, "false is false");4}5test();6assert() function7assert(value[, message])8function test() {9 assert(true, "true is true");10 assert(false, "false is false");11}12test();13assert.deepEqual() function14assert.deepEqual(actual, expected[, message])15function test() {16 assert.deepEqual([1,2,3,4], [1,2,3

Full Screen

Using AI Code Generation

copy

Full Screen

1function test() {2 assert_true(true);3}4{5 "test": {6 "test": {7 }8 },9}

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