Tests different invalid parameters that should raise an exception.
()
| 582 | # ============================================================================= |
| 583 | # Tests that are specific to this descriptor. |
| 584 | def test_exceptions(): |
| 585 | """Tests different invalid parameters that should raise an |
| 586 | exception. |
| 587 | """ |
| 588 | # Weighting needs to be provided for periodic system and terms k>1 |
| 589 | with pytest.raises(ValueError) as excinfo: |
| 590 | setup = copy.copy(default_k2) |
| 591 | setup["weighting"] = None |
| 592 | MBTR( |
| 593 | species=["H"], |
| 594 | **setup, |
| 595 | periodic=True, |
| 596 | ) |
| 597 | msg = "Periodic systems need to have a weighting function." |
| 598 | assert msg == str(excinfo.value) |
| 599 | |
| 600 | with pytest.raises(ValueError) as excinfo: |
| 601 | setup = copy.copy(default_k2) |
| 602 | setup["weighting"] = {"function": "unity"} |
| 603 | MBTR( |
| 604 | species=["H"], |
| 605 | **setup, |
| 606 | periodic=True, |
| 607 | ) |
| 608 | assert msg == str(excinfo.value) |
| 609 | |
| 610 | # Invalid weighting function |
| 611 | with pytest.raises(ValueError) as excinfo: |
| 612 | setup = copy.copy(default_k1) |
| 613 | setup["weighting"] = {"function": "exp", "threshold": 1, "scale": 1} |
| 614 | MBTR( |
| 615 | species=[1], |
| 616 | **setup, |
| 617 | periodic=True, |
| 618 | ) |
| 619 | msg = "Unknown weighting function specified for k=1. Please use one of the following: ['unity']" |
| 620 | assert msg == str(excinfo.value) |
| 621 | |
| 622 | with pytest.raises(ValueError) as excinfo: |
| 623 | setup = copy.copy(default_k2) |
| 624 | setup["weighting"] = {"function": "none"} |
| 625 | MBTR( |
| 626 | species=[1], |
| 627 | **setup, |
| 628 | periodic=True, |
| 629 | ) |
| 630 | msg = "Unknown weighting function specified for k=2. Please use one of the following: ['exp', 'inverse_square', 'unity']" |
| 631 | assert msg == str(excinfo.value) |
| 632 | |
| 633 | with pytest.raises(ValueError) as excinfo: |
| 634 | setup = copy.copy(default_k3) |
| 635 | setup["weighting"] = {"function": "none"} |
| 636 | MBTR( |
| 637 | species=[1], |
| 638 | **setup, |
| 639 | periodic=True, |
| 640 | ) |
| 641 | msg = "Unknown weighting function specified for k=3. Please use one of the following: ['exp', 'smooth_cutoff', 'unity']" |