Show More
@@ -742,3 +742,23 b' def test_alias_magic():' | |||
|
742 | 742 | ip.run_line_magic('alias_magic', '--line env_alias env') |
|
743 | 743 | nt.assert_equal(ip.run_line_magic('env', ''), |
|
744 | 744 | ip.run_line_magic('env_alias', '')) |
|
745 | ||
|
746 | def test_save(): | |
|
747 | """Test %save.""" | |
|
748 | ip = get_ipython() | |
|
749 | ip.history_manager.reset() # Clear any existing history. | |
|
750 | cmds = [u"a=1", u"def b():\n return a**2", u"print(a, b())"] | |
|
751 | for i, cmd in enumerate(cmds, start=1): | |
|
752 | ip.history_manager.store_inputs(i, cmd) | |
|
753 | with TemporaryDirectory() as tmpdir: | |
|
754 | file = os.path.join(tmpdir, "testsave.py") | |
|
755 | ip.run_line_magic("save", "%s 1-10" % file) | |
|
756 | with open(file) as f: | |
|
757 | content = f.read() | |
|
758 | nt.assert_equal(content.count(cmds[0]), 1) | |
|
759 | nt.assert_true('coding: utf-8' in content) | |
|
760 | ip.run_line_magic("save", "-a %s 1-10" % file) | |
|
761 | with open(file) as f: | |
|
762 | content = f.read() | |
|
763 | nt.assert_equal(content.count(cmds[0]), 2) | |
|
764 | nt.assert_true('coding: utf-8' in content) |
General Comments 0
You need to be logged in to leave comments.
Login now