diff options
author | Kevin Van Brunt <kmvanbrunt@gmail.com> | 2019-07-29 19:51:04 -0400 |
---|---|---|
committer | Kevin Van Brunt <kmvanbrunt@gmail.com> | 2019-07-29 19:51:04 -0400 |
commit | 9d9e449bba87500b0b7bd83fa35417ef6d66ba08 (patch) | |
tree | 446ba90ec71d3d8d337261b82a8723a2429d5447 /tests/test_history.py | |
parent | 96d006df4cb3a73dc9cd9bb6e171c4e34acfd2c9 (diff) | |
download | cmd2-git-9d9e449bba87500b0b7bd83fa35417ef6d66ba08.tar.gz |
Added unit test
Diffstat (limited to 'tests/test_history.py')
-rw-r--r-- | tests/test_history.py | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/tests/test_history.py b/tests/test_history.py index 2e6f13b9..9752ed07 100644 --- a/tests/test_history.py +++ b/tests/test_history.py @@ -638,6 +638,27 @@ def test_history_file_is_directory(capsys): _, err = capsys.readouterr() assert 'is a directory' in err +def test_history_can_create_directory(mocker): + # Mock out atexit.register so the persistent file doesn't written when this function + # exists because we will be deleting the directory it needs to go to. + mock_register = mocker.patch('atexit.register') + + # Create a temp path for us to use and let it get deleted + with tempfile.TemporaryDirectory() as test_dir: + pass + assert not os.path.isdir(test_dir) + + # Add some subdirectories for the complete history file directory + hist_file_dir = os.path.join(test_dir, 'subdir1', 'subdir2') + hist_file = os.path.join(hist_file_dir, 'hist_file') + + # Make sure cmd2 creates the history file directory + cmd2.Cmd(persistent_history_file=hist_file) + assert os.path.isdir(hist_file_dir) + + # Cleanup + os.rmdir(hist_file_dir) + def test_history_cannot_create_directory(mocker, capsys): mock_open = mocker.patch('os.makedirs') mock_open.side_effect = OSError |