File tree Expand file tree Collapse file tree 1 file changed +39
-0
lines changed Expand file tree Collapse file tree 1 file changed +39
-0
lines changed Original file line number Diff line number Diff line change 1+ import  pytest 
2+ 
3+ from  diffpy .cmi .cli  import  main 
4+ 
5+ 
6+ def  test_cli_help (capsys ):
7+     """Test that the CLI help message is displayed correctly.""" 
8+     with  pytest .raises (SystemExit ) as  exc :
9+         main (["--help" , "-h" ])
10+     assert  exc .value .code  ==  0 
11+     out , _  =  capsys .readouterr ()
12+     assert  "Welcome to diffpy.cmi"  in  out 
13+ 
14+ 
15+ def  test_example_list (capsys ):
16+     """Test that the example listing works.""" 
17+     rc  =  main (["example" , "list" ])
18+     assert  rc  ==  0 
19+     out , _  =  capsys .readouterr ()
20+     # test specific known pack and example 
21+     assert  "ch03NiModelling"  in  out 
22+     assert  "pdf"  in  out 
23+ 
24+ 
25+ def  test_example_copy (monkeypatch , tmp_path ):
26+     """Test that an example can be copied to the current directory.""" 
27+     # create a fake example 
28+     fake_examples  =  tmp_path  /  "docs"  /  "examples" 
29+     src  =  fake_examples  /  "pack1"  /  "ex1" 
30+     src .mkdir (parents = True )
31+     monkeypatch .setattr (
32+         "diffpy.cmi.cli._installed_examples_dir" ,
33+         lambda : fake_examples ,
34+     )
35+     cwd  =  tmp_path 
36+     monkeypatch .chdir (cwd )
37+     rc  =  main (["example" , "copy" , "pdf/ch03NiModelling" ])
38+     assert  rc  ==  0 
39+     assert  (cwd  /  "ch03NiModelling" ).exists ()
 
 
   
 
     
   
   
          
    
    
     
    
      
     
     
    You can’t perform that action at this time.
  
 
    
  
    
      
        
     
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments