1414import logging
1515import unittest
1616
17+ import pytest
1718import numpy
1819import numpy .linalg
1920import scipy .linalg
@@ -406,9 +407,10 @@ def test_get_lowest_z_real(self):
406407 initial_guess = 1.0j * numpy .random .rand (dimension , n_lowest )
407408 numpy .random .seed (dimension * 2 )
408409 initial_guess += numpy .random .rand (dimension , n_lowest )
409- success , eigen_values , eigen_vectors = davidson .get_lowest_n (
410- n_lowest , initial_guess , max_iterations = 10
411- )
410+ with pytest .warns (RuntimeWarning ):
411+ success , eigen_values , eigen_vectors = davidson .get_lowest_n (
412+ n_lowest , initial_guess , max_iterations = 10
413+ )
412414
413415 # one half of the eigenvalues is -1 and the other half is +1, together
414416 # with the coefficient.
@@ -436,9 +438,13 @@ def test_get_lowest_y_real_fail(self):
436438 initial_guess = 1.0j * numpy .random .rand (dimension , n_lowest )
437439 numpy .random .seed (dimension * 2 )
438440 initial_guess += numpy .random .rand (dimension , n_lowest )
439- success , _ , eigen_vectors = davidson .get_lowest_n (
440- n_lowest , initial_guess , max_iterations = 10
441- )
441+ with pytest .warns (
442+ RuntimeWarning ,
443+ match = ("Unable to get real only eigenvectors|Initial guess is not real only!" ),
444+ ):
445+ success , _ , eigen_vectors = davidson .get_lowest_n (
446+ n_lowest , initial_guess , max_iterations = 10
447+ )
442448
443449 self .assertFalse (success )
444450
@@ -458,9 +464,13 @@ def test_get_lowest_y_real(self):
458464 initial_guess = 1.0j * numpy .random .rand (dimension , n_lowest )
459465 numpy .random .seed (dimension * 2 )
460466 initial_guess += numpy .random .rand (dimension , n_lowest )
461- success , eigen_values , eigen_vectors = davidson .get_lowest_n (
462- n_lowest , initial_guess , max_iterations = 10
463- )
467+ with pytest .warns (
468+ RuntimeWarning ,
469+ match = ("Unable to get real only eigenvectors|Initial guess is not real only!" ),
470+ ):
471+ success , eigen_values , eigen_vectors = davidson .get_lowest_n (
472+ n_lowest , initial_guess , max_iterations = 10
473+ )
464474
465475 # one half of the eigenvalues is -1 and the other half is +1, together
466476 # with the coefficient.
@@ -487,9 +497,13 @@ def test_get_lowest_y_complex(self):
487497 initial_guess = 1.0j * numpy .random .rand (dimension , n_lowest )
488498 numpy .random .seed (dimension * 2 )
489499 initial_guess += numpy .random .rand (dimension , n_lowest )
490- success , eigen_values , eigen_vectors = davidson .get_lowest_n (
491- n_lowest , initial_guess , max_iterations = 10
492- )
500+ with pytest .warns (
501+ RuntimeWarning ,
502+ match = ("Unable to get real only eigenvectors|Initial guess is not real only!" ),
503+ ):
504+ success , eigen_values , eigen_vectors = davidson .get_lowest_n (
505+ n_lowest , initial_guess , max_iterations = 10
506+ )
493507
494508 # one half of the eigenvalues is -1 and the other half is +1, together
495509 # with the coefficient.
@@ -658,7 +672,8 @@ def test_append_vectors_big_col(self):
658672 """Test append_random_vectors() with too many failed trial."""
659673 row = 10
660674 vectors = numpy .eye (row , row )
661- new_vectors = append_random_vectors (vectors , 1 )
675+ with pytest .warns (RuntimeWarning ):
676+ new_vectors = append_random_vectors (vectors , 1 )
662677
663678 self .assertTrue (numpy .allclose (new_vectors , vectors ))
664679
0 commit comments