@@ -499,6 +499,95 @@ def test_scan_for_configure_pypi(self):
499499 self .assertEqual (self .reqs .requires ['python3' ], pypi_requires )
500500 self .assertEqual (ssummary , summary )
501501
502+ def test_scan_for_configure_pypi_no_name_in_json (self ):
503+ """
504+ Test scan_for_configure when distutils is being used for the build
505+ pattern to test connecting to pypi but not getting a name back.
506+ """
507+ orig_summary = buildreq .specdescription .default_summary
508+ orig_sscore = buildreq .specdescription .default_summary_score
509+ orig_pypi_name = buildreq .pypidata .get_pypi_name
510+ orig_pypi_meta = buildreq .pypidata .get_pypi_metadata
511+ name = "pypi-name"
512+ content = json .dumps ({})
513+ buildreq .pypidata .pkg_search = MagicMock (return_value = False )
514+ buildreq .pypidata .get_pypi_metadata = MagicMock (return_value = content )
515+ with tempfile .TemporaryDirectory () as tmpd :
516+ conf = config .Config (tmpd )
517+ conf .config_opts ['use_ninja' ] = False
518+ os .mkdir (os .path .join (tmpd , 'subdir' ))
519+ open (os .path .join (tmpd , 'subdir' , 'pyproject.toml' ), 'w' ).close ()
520+ self .reqs .scan_for_configure (os .path .join (tmpd , 'subdir' ), name , conf )
521+
522+ post_summary = buildreq .specdescription .default_summary
523+ buildreq .specdescription .default_summary = orig_summary
524+ buildreq .specdescription .default_summary_score = orig_sscore
525+ buildreq .pypidata .get_pypi_name = orig_pypi_name
526+ buildreq .pypidata .get_pypi_metadata = orig_pypi_meta
527+
528+ self .assertEqual (self .reqs .pypi_provides , "name" )
529+ self .assertEqual (post_summary , orig_summary )
530+
531+ def test_scan_for_configure_pypi_no_json (self ):
532+ """
533+ Test scan_for_configure when distutils is being used for the build
534+ pattern to test being unable to connect to pypi.
535+ """
536+ orig_summary = buildreq .specdescription .default_summary
537+ orig_sscore = buildreq .specdescription .default_summary_score
538+ orig_pypi_name = buildreq .pypidata .get_pypi_name
539+ orig_pypi_meta = buildreq .pypidata .get_pypi_metadata
540+ name = "pypi-name"
541+ buildreq .pypidata .pkg_search = MagicMock (return_value = False )
542+ buildreq .pypidata .get_pypi_metadata = MagicMock (return_value = "" )
543+ with tempfile .TemporaryDirectory () as tmpd :
544+ conf = config .Config (tmpd )
545+ conf .config_opts ['use_ninja' ] = False
546+ os .mkdir (os .path .join (tmpd , 'subdir' ))
547+ open (os .path .join (tmpd , 'subdir' , 'pyproject.toml' ), 'w' ).close ()
548+ self .reqs .scan_for_configure (os .path .join (tmpd , 'subdir' ), name , conf )
549+
550+ post_summary = buildreq .specdescription .default_summary
551+ buildreq .specdescription .default_summary = orig_summary
552+ buildreq .specdescription .default_summary_score = orig_sscore
553+ buildreq .pypidata .get_pypi_name = orig_pypi_name
554+ buildreq .pypidata .get_pypi_metadata = orig_pypi_meta
555+
556+ self .assertEqual (self .reqs .pypi_provides , "name" )
557+ self .assertEqual (post_summary , orig_summary )
558+
559+ def test_scan_for_configure_pypi_bad_json (self ):
560+ """
561+ Test scan_for_configure when distutils is being used for the build
562+ pattern to test being given bad json data.
563+ """
564+ orig_summary = buildreq .specdescription .default_summary
565+ orig_sscore = buildreq .specdescription .default_summary_score
566+ orig_pypi_name = buildreq .pypidata .get_pypi_name
567+ orig_pypi_meta = buildreq .pypidata .get_pypi_metadata
568+ orig_json_loads = buildreq .json .loads
569+ name = "pypi-name"
570+ content = json .dumps ({})
571+ buildreq .pypidata .pkg_search = MagicMock (return_value = False )
572+ buildreq .pypidata .get_pypi_metadata = MagicMock (return_value = content )
573+ buildreq .json .loads = MagicMock (side_effect = json .JSONDecodeError ("" , "" , 0 ))
574+ with tempfile .TemporaryDirectory () as tmpd :
575+ conf = config .Config (tmpd )
576+ conf .config_opts ['use_ninja' ] = False
577+ os .mkdir (os .path .join (tmpd , 'subdir' ))
578+ open (os .path .join (tmpd , 'subdir' , 'pyproject.toml' ), 'w' ).close ()
579+ self .reqs .scan_for_configure (os .path .join (tmpd , 'subdir' ), name , conf )
580+
581+ post_summary = buildreq .specdescription .default_summary
582+ buildreq .specdescription .default_summary = orig_summary
583+ buildreq .specdescription .default_summary_score = orig_sscore
584+ buildreq .pypidata .get_pypi_name = orig_pypi_name
585+ buildreq .pypidata .get_pypi_metadata = orig_pypi_meta
586+ buildreq .json .loads = orig_json_loads
587+
588+ self .assertEqual (self .reqs .pypi_provides , "name" )
589+ self .assertEqual (post_summary , orig_summary )
590+
502591 def test_scan_for_configure_pypi_override (self ):
503592 """
504593 Test scan_for_configure when distutils is being used for the build
0 commit comments