Show More
@@ -777,3 +777,22 def test_save(): | |||||
777 | content = f.read() |
|
777 | content = f.read() | |
778 | nt.assert_equal(content.count(cmds[0]), 2) |
|
778 | nt.assert_equal(content.count(cmds[0]), 2) | |
779 | nt.assert_true('coding: utf-8' in content) |
|
779 | nt.assert_true('coding: utf-8' in content) | |
|
780 | ||||
|
781 | ||||
|
782 | def test_store(): | |||
|
783 | """Test %store.""" | |||
|
784 | ip = get_ipython() | |||
|
785 | ip.run_line_magic('load_ext', 'storemagic') | |||
|
786 | ||||
|
787 | # make sure the storage is empty | |||
|
788 | ip.run_line_magic('store', '-z') | |||
|
789 | ip.user_ns['var'] = 42 | |||
|
790 | ip.run_line_magic('store', 'var') | |||
|
791 | ip.user_ns['var'] = 39 | |||
|
792 | ip.run_line_magic('store', '-r') | |||
|
793 | nt.assert_equal(ip.user_ns['var'], 42) | |||
|
794 | ||||
|
795 | ip.run_line_magic('store', '-d var') | |||
|
796 | ip.user_ns['var'] = 39 | |||
|
797 | ip.run_line_magic('store' , '-r') | |||
|
798 | nt.assert_equal(ip.user_ns['var'], 39) |
@@ -140,7 +140,7 class StoreMagics(Magics): | |||||
140 |
|
140 | |||
141 | # run without arguments -> list variables & values |
|
141 | # run without arguments -> list variables & values | |
142 | elif not args: |
|
142 | elif not args: | |
143 |
vars = |
|
143 | vars = db.keys('autorestore/*') | |
144 | vars.sort() |
|
144 | vars.sort() | |
145 | if vars: |
|
145 | if vars: | |
146 | size = max(map(len, vars)) |
|
146 | size = max(map(len, vars)) | |
@@ -186,9 +186,9 class StoreMagics(Magics): | |||||
186 | except KeyError: |
|
186 | except KeyError: | |
187 | # it might be an alias |
|
187 | # it might be an alias | |
188 | # This needs to be refactored to use the new AliasManager stuff. |
|
188 | # This needs to be refactored to use the new AliasManager stuff. | |
189 |
if args[0] in |
|
189 | if args[0] in ip.alias_manager: | |
190 | name = args[0] |
|
190 | name = args[0] | |
191 |
nargs, cmd = |
|
191 | nargs, cmd = ip.alias_manager.alias_table[ name ] | |
192 | staliases = db.get('stored_aliases',{}) |
|
192 | staliases = db.get('stored_aliases',{}) | |
193 | staliases[ name ] = cmd |
|
193 | staliases[ name ] = cmd | |
194 | db['stored_aliases'] = staliases |
|
194 | db['stored_aliases'] = staliases | |
@@ -207,7 +207,7 class StoreMagics(Magics): | |||||
207 | """ % (args[0], obj) ) |
|
207 | """ % (args[0], obj) ) | |
208 | return |
|
208 | return | |
209 | #pickled = pickle.dumps(obj) |
|
209 | #pickled = pickle.dumps(obj) | |
210 |
|
|
210 | db[ 'autorestore/' + args[0] ] = obj | |
211 | print "Stored '%s' (%s)" % (args[0], obj.__class__.__name__) |
|
211 | print "Stored '%s' (%s)" % (args[0], obj.__class__.__name__) | |
212 |
|
212 | |||
213 |
|
213 |
General Comments 0
You need to be logged in to leave comments.
Login now