@@ -812,7 +812,29 @@ def test_edit_file_with_spaces(base_app, request, monkeypatch):
812
812
# We think we have an editor, so should expect a system call
813
813
m .assert_called_once_with ('"{}" "{}"' .format (base_app .editor , filename ))
814
814
815
- def test_edit_number (base_app , monkeypatch ):
815
+ def test_edit_blank (base_app , monkeypatch ):
816
+ # Set a fake editor just to make sure we have one. We aren't really going to call it due to the mock
817
+ base_app .editor = 'fooedit'
818
+
819
+ # Mock out the os.system call so we don't actually open an editor
820
+ m = mock .MagicMock (name = 'system' )
821
+ monkeypatch .setattr ("os.system" , m )
822
+
823
+ # Run help command just so we have a command in history
824
+ run_cmd (base_app , 'help' )
825
+
826
+ run_cmd (base_app , 'edit' )
827
+
828
+ # We have an editor, so should expect a system call
829
+ m .assert_called_once ()
830
+
831
+ def test_edit_empty_history (base_app , capsys ):
832
+ run_cmd (base_app , 'edit' )
833
+ out , err = capsys .readouterr ()
834
+ assert out == ''
835
+ assert err == 'ERROR: edit must be called with argument if history is empty\n '
836
+
837
+ def test_edit_valid_positive_number (base_app , monkeypatch ):
816
838
# Set a fake editor just to make sure we have one. We aren't really going to call it due to the mock
817
839
base_app .editor = 'fooedit'
818
840
@@ -828,7 +850,7 @@ def test_edit_number(base_app, monkeypatch):
828
850
# We have an editor, so should expect a system call
829
851
m .assert_called_once ()
830
852
831
- def test_edit_blank (base_app , monkeypatch ):
853
+ def test_edit_valid_negative_number (base_app , monkeypatch ):
832
854
# Set a fake editor just to make sure we have one. We aren't really going to call it due to the mock
833
855
base_app .editor = 'fooedit'
834
856
@@ -839,16 +861,42 @@ def test_edit_blank(base_app, monkeypatch):
839
861
# Run help command just so we have a command in history
840
862
run_cmd (base_app , 'help' )
841
863
842
- run_cmd (base_app , 'edit' )
864
+ run_cmd (base_app , 'edit "-1" ' )
843
865
844
866
# We have an editor, so should expect a system call
845
867
m .assert_called_once ()
846
868
847
- def test_edit_empty_history (base_app , capsys ):
848
- run_cmd (base_app , 'edit' )
849
- out , err = capsys .readouterr ()
850
- assert out == ''
851
- assert err == 'ERROR: edit must be called with argument if history is empty\n '
869
+ def test_edit_invalid_positive_number (base_app , monkeypatch ):
870
+ # Set a fake editor just to make sure we have one. We aren't really going to call it due to the mock
871
+ base_app .editor = 'fooedit'
872
+
873
+ # Mock out the os.system call so we don't actually open an editor
874
+ m = mock .MagicMock (name = 'system' )
875
+ monkeypatch .setattr ("os.system" , m )
876
+
877
+ # Run help command just so we have a command in history
878
+ run_cmd (base_app , 'help' )
879
+
880
+ run_cmd (base_app , 'edit 23' )
881
+
882
+ # History index is invalid, so should expect a system call
883
+ m .assert_not_called ()
884
+
885
+ def test_edit_invalid_negative_number (base_app , monkeypatch ):
886
+ # Set a fake editor just to make sure we have one. We aren't really going to call it due to the mock
887
+ base_app .editor = 'fooedit'
888
+
889
+ # Mock out the os.system call so we don't actually open an editor
890
+ m = mock .MagicMock (name = 'system' )
891
+ monkeypatch .setattr ("os.system" , m )
892
+
893
+ # Run help command just so we have a command in history
894
+ run_cmd (base_app , 'help' )
895
+
896
+ run_cmd (base_app , 'edit "-23"' )
897
+
898
+ # History index is invalid, so should expect a system call
899
+ m .assert_not_called ()
852
900
853
901
854
902
def test_base_py_interactive (base_app ):
0 commit comments