@@ -437,3 +437,85 @@ def test_that_the_tiffdatetimetest_correctly_interprets_exit_code_0_and_1(
437437 )
438438 test_status = test .get_status ()
439439 assert test_status == TestStatus .FAIL
440+
441+
442+ class TestH5adHtanValidatorTest :
443+ @pytest .fixture (scope = "function" , autouse = True )
444+ def setup_method (self , test_targets ):
445+ self .good_h5ad_target = test_targets ["htan_good_h5ad" ]
446+ self .good_h5ad_test = tests .H5adHtanValidatorTest (self .good_h5ad_target )
447+ self .bad_h5ad_target = test_targets ["htan_bad_h5ad" ]
448+ self .bad_h5ad_test = tests .H5adHtanValidatorTest (self .bad_h5ad_target )
449+ self .txt_target = test_targets ["good_txt" ]
450+ self .txt_test = tests .H5adHtanValidatorTest (self .txt_target )
451+
452+ def test_that_the_command_is_produced (self ):
453+ process = self .good_h5ad_test .generate_process ()
454+ assert "/usr/local/bin/h5ad.py" in process .command
455+
456+ @docker_enabled_test
457+ def test_that_the_exit_code_is_1_when_it_should_be (self ):
458+ process = self .bad_h5ad_test .generate_process ()
459+ executor = DockerExecutor (
460+ process .container , process .command , self .bad_h5ad_target .file .url
461+ )
462+ executor .execute ()
463+ assert "File: htan_bad.h5ad" in executor .std_out
464+ assert "Cellxgene run has errors. " in executor .std_out
465+ assert "HTAN Validation Failed." in executor .std_out
466+ assert "'cellxgene-schema output: Starting validation" in executor .std_out
467+ assert "HTAN-specific Validation Errors:" in executor .std_out
468+ assert executor .exit_code == "1"
469+
470+ @docker_enabled_test
471+ def test_that_the_exit_code_is_0_when_it_should_be (self ):
472+ process = self .good_h5ad_test .generate_process ()
473+ executor = DockerExecutor (
474+ process .container , process .command , self .good_h5ad_target .file .url
475+ )
476+ executor .execute ()
477+ assert "File: htan_good.h5ad" in executor .std_out
478+ assert "Cellxgene run successful." in executor .std_out
479+ assert "Validation Passed!" in executor .std_out
480+ assert executor .exit_code == "0"
481+
482+ @docker_enabled_test
483+ def test_that_wrong_file_type_has_1_exit_code (self ):
484+ process = self .txt_test .generate_process ()
485+ executor = DockerExecutor (
486+ process .container , process .command , self .txt_target .file .url
487+ )
488+ executor .execute ()
489+ print (executor .std_out )
490+ assert executor .std_out == (
491+ "HTAN h5ad File Validator\n "
492+ "File: test.txt\n "
493+ "An error occurred while trying to open test.txt\n "
494+ "Unable to synchronously open file (file signature not found)\n "
495+ "\n "
496+ )
497+ assert executor .exit_code == "1"
498+
499+ def test_that_the_test_correctly_interprets_exit_code_0_and_1 (self , mocker ):
500+ # 1 is pass, 0 is fail
501+ with TemporaryDirectory () as tmp_dir :
502+ path_0 = Path (tmp_dir , "code_0.txt" )
503+ path_1 = Path (tmp_dir , "code_1.txt" )
504+ path_0 .write_text ("0" )
505+ path_1 .write_text ("1" )
506+ fail_outputs = {"std_out" : path_1 , "std_err" : path_1 , "exit_code" : path_0 }
507+ pass_outputs = {"std_out" : path_0 , "std_err" : path_0 , "exit_code" : path_1 }
508+
509+ test = tests .TiffDateTimeTest (self .good_h5ad_target )
510+ mocker .patch .object (
511+ test , "_find_process_outputs" , return_value = pass_outputs
512+ )
513+ test_status = test .get_status ()
514+ assert test_status == TestStatus .PASS
515+
516+ test = tests .TiffDateTimeTest (self .bad_h5ad_target )
517+ mocker .patch .object (
518+ test , "_find_process_outputs" , return_value = fail_outputs
519+ )
520+ test_status = test .get_status ()
521+ assert test_status == TestStatus .FAIL
0 commit comments