File tree Expand file tree Collapse file tree 1 file changed +21
-0
lines changed Expand file tree Collapse file tree 1 file changed +21
-0
lines changed Original file line number Diff line number Diff line change @@ -638,6 +638,27 @@ def test_history_file_is_directory(capsys):
638
638
_ , err = capsys .readouterr ()
639
639
assert 'is a directory' in err
640
640
641
+ def test_history_can_create_directory (mocker ):
642
+ # Mock out atexit.register so the persistent file doesn't written when this function
643
+ # exists because we will be deleting the directory it needs to go to.
644
+ mock_register = mocker .patch ('atexit.register' )
645
+
646
+ # Create a temp path for us to use and let it get deleted
647
+ with tempfile .TemporaryDirectory () as test_dir :
648
+ pass
649
+ assert not os .path .isdir (test_dir )
650
+
651
+ # Add some subdirectories for the complete history file directory
652
+ hist_file_dir = os .path .join (test_dir , 'subdir1' , 'subdir2' )
653
+ hist_file = os .path .join (hist_file_dir , 'hist_file' )
654
+
655
+ # Make sure cmd2 creates the history file directory
656
+ cmd2 .Cmd (persistent_history_file = hist_file )
657
+ assert os .path .isdir (hist_file_dir )
658
+
659
+ # Cleanup
660
+ os .rmdir (hist_file_dir )
661
+
641
662
def test_history_cannot_create_directory (mocker , capsys ):
642
663
mock_open = mocker .patch ('os.makedirs' )
643
664
mock_open .side_effect = OSError
You can’t perform that action at this time.
0 commit comments