|
19 | 19 | from docx.opc.pkgreader import PackageReader |
20 | 20 |
|
21 | 21 | from ..unitutil import ( |
22 | | - cls_attr_mock, class_mock, instance_mock, loose_mock, method_mock |
| 22 | + cls_attr_mock, class_mock, function_mock, instance_mock, loose_mock, |
| 23 | + method_mock |
23 | 24 | ) |
24 | 25 |
|
25 | 26 |
|
@@ -384,15 +385,14 @@ class DescribePartFactory(object): |
384 | 385 | def it_constructs_part_from_selector_if_defined( |
385 | 386 | self, cls_selector_fixture): |
386 | 387 | # fixture ---------------------- |
387 | | - (cls_selector_fn_, partname, content_type, reltype, blob, package, |
388 | | - CustomPartClass_, part_of_custom_type_) = cls_selector_fixture |
| 388 | + (cls_selector_fn_, part_load_params, CustomPartClass_, |
| 389 | + part_of_custom_type_) = cls_selector_fixture |
| 390 | + partname, content_type, reltype, blob, package = part_load_params |
389 | 391 | # exercise --------------------- |
390 | 392 | PartFactory.part_class_selector = cls_selector_fn_ |
391 | 393 | part = PartFactory(partname, content_type, reltype, blob, package) |
392 | 394 | # verify ----------------------- |
393 | | - cls_selector_fn_.__func__.assert_called_once_with( |
394 | | - content_type, reltype |
395 | | - ) |
| 395 | + cls_selector_fn_.assert_called_once_with(content_type, reltype) |
396 | 396 | CustomPartClass_.load.assert_called_once_with( |
397 | 397 | partname, content_type, blob, package |
398 | 398 | ) |
@@ -430,25 +430,34 @@ def blob_(self, request): |
430 | 430 | def blob_2_(self, request): |
431 | 431 | return instance_mock(request, str) |
432 | 432 |
|
| 433 | + @pytest.fixture |
| 434 | + def cls_method_fn_(self, request, cls_selector_fn_): |
| 435 | + return function_mock( |
| 436 | + request, 'docx.opc.package.cls_method_fn', |
| 437 | + return_value=cls_selector_fn_ |
| 438 | + ) |
| 439 | + |
433 | 440 | @pytest.fixture |
434 | 441 | def cls_selector_fixture( |
435 | | - self, request, cls_selector_fn_, partname_, content_type_, |
436 | | - reltype_, blob_, package_, CustomPartClass_, |
437 | | - part_of_custom_type_): |
| 442 | + self, request, cls_selector_fn_, cls_method_fn_, part_load_params, |
| 443 | + CustomPartClass_, part_of_custom_type_): |
438 | 444 | def reset_part_class_selector(): |
439 | 445 | PartFactory.part_class_selector = original_part_class_selector |
440 | 446 | original_part_class_selector = PartFactory.part_class_selector |
441 | 447 | request.addfinalizer(reset_part_class_selector) |
442 | 448 | return ( |
443 | | - cls_selector_fn_, partname_, content_type_, reltype_, |
444 | | - blob_, package_, CustomPartClass_, part_of_custom_type_ |
| 449 | + cls_selector_fn_, part_load_params, CustomPartClass_, |
| 450 | + part_of_custom_type_ |
445 | 451 | ) |
446 | 452 |
|
447 | 453 | @pytest.fixture |
448 | 454 | def cls_selector_fn_(self, request, CustomPartClass_): |
449 | 455 | cls_selector_fn_ = loose_mock(request) |
| 456 | + # Python 3 version |
| 457 | + cls_selector_fn_.return_value = CustomPartClass_ |
| 458 | + # Python 2 version |
450 | 459 | cls_selector_fn_.__func__ = loose_mock( |
451 | | - request, name='__func__', return_value=CustomPartClass_ |
| 460 | + request, name='__func__', return_value=cls_selector_fn_ |
452 | 461 | ) |
453 | 462 | return cls_selector_fn_ |
454 | 463 |
|
@@ -482,6 +491,11 @@ def package_(self, request): |
482 | 491 | def package_2_(self, request): |
483 | 492 | return instance_mock(request, OpcPackage) |
484 | 493 |
|
| 494 | + @pytest.fixture |
| 495 | + def part_load_params( |
| 496 | + self, partname_, content_type_, reltype_, blob_, package_): |
| 497 | + return partname_, content_type_, reltype_, blob_, package_ |
| 498 | + |
485 | 499 | @pytest.fixture |
486 | 500 | def part_of_custom_type_(self, request): |
487 | 501 | return instance_mock(request, Part) |
|
0 commit comments