import tempfile, os

import nose.tools as nt

ip = get_ipython()
ip.magic('load_ext storemagic')

def test_store_restore():
    ip.user_ns['foo'] = 78
    ip.magic('alias bar echo "hello"')
    tmpd = tempfile.mkdtemp()
    ip.magic('cd ' + tmpd)
    ip.magic('store foo')
    ip.magic('store bar')
    
    # Check storing
    nt.assert_equal(ip.db['autorestore/foo'], 78)
    nt.assert_in('bar', ip.db['stored_aliases'])
    
    # Remove those items
    ip.user_ns.pop('foo', None)
    ip.alias_manager.undefine_alias('bar')
    ip.magic('cd -')
    ip.user_ns['_dh'][:] = []
    
    # Check restoring
    ip.magic('store -r')
    nt.assert_equal(ip.user_ns['foo'], 78)
    nt.assert_in('bar', ip.alias_manager.alias_table)
    nt.assert_in(tmpd, ip.user_ns['_dh'])
    
    os.rmdir(tmpd)

import tempfile, os

import nose.tools as nt

ip = get_ipython()
ip.magic('load_ext storemagic')

def test_store_restore():
    ip.user_ns['foo'] = 78
    ip.magic('alias bar echo "hello"')
    tmpd = tempfile.mkdtemp()
    ip.magic('cd ' + tmpd)
    ip.magic('store foo')
    ip.magic('store bar')
    
    # Check storing
    nt.assert_equal(ip.db['autorestore/foo'], 78)
    nt.assert_in('bar', ip.db['stored_aliases'])
    
    # Remove those items
    ip.user_ns.pop('foo', None)
    ip.alias_manager.undefine_alias('bar')
    ip.magic('cd -')
    ip.user_ns['_dh'][:] = []
    
    # Check restoring
    ip.magic('store -r')
    nt.assert_equal(ip.user_ns['foo'], 78)
    nt.assert_in('bar', ip.alias_manager.alias_table)
    nt.assert_in(os.path.realpath(tmpd), ip.user_ns['_dh'])
    
    os.rmdir(tmpd)

Store magic test. On MacOSX the temp dir in /var is symlinked into /private/var thus making this comparison fail. This is solved by using os.path.realpath to expand the tempdir into is's real directory.
Store magic test. On MacOSX the temp dir in /var is symlinked into /private/var thus making this comparison fail. This is solved by using os.path.realpath to expand the tempdir into is's real directory.

  import tempfile, os
  
  import nose.tools as nt
  
  ip = get_ipython()
  ip.magic('load_ext storemagic')
  
  def test_store_restore():
      ip.user_ns['foo'] = 78
      ip.magic('alias bar echo "hello"')
      tmpd = tempfile.mkdtemp()
      ip.magic('cd ' + tmpd)
      ip.magic('store foo')
      ip.magic('store bar')
      
      # Check storing
      nt.assert_equal(ip.db['autorestore/foo'], 78)
      nt.assert_in('bar', ip.db['stored_aliases'])
      
      # Remove those items
      ip.user_ns.pop('foo', None)
      ip.alias_manager.undefine_alias('bar')
      ip.magic('cd -')
      ip.user_ns['_dh'][:] = []
      
      # Check restoring
      ip.magic('store -r')
      nt.assert_equal(ip.user_ns['foo'], 78)
      nt.assert_in('bar', ip.alias_manager.alias_table)
-     nt.assert_in(tmpd, ip.user_ns['_dh'])
+     nt.assert_in(os.path.realpath(tmpd), ip.user_ns['_dh'])
      
      os.rmdir(tmpd)
  
Store magic test. On MacOSX the temp dir in /var is symlinked into /private/var thus making this comparison fail. This is solved by using os.path.realpath to expand the tempdir into is's real directory.
## Code Before:
import tempfile, os

import nose.tools as nt

ip = get_ipython()
ip.magic('load_ext storemagic')

def test_store_restore():
    ip.user_ns['foo'] = 78
    ip.magic('alias bar echo "hello"')
    tmpd = tempfile.mkdtemp()
    ip.magic('cd ' + tmpd)
    ip.magic('store foo')
    ip.magic('store bar')
    
    # Check storing
    nt.assert_equal(ip.db['autorestore/foo'], 78)
    nt.assert_in('bar', ip.db['stored_aliases'])
    
    # Remove those items
    ip.user_ns.pop('foo', None)
    ip.alias_manager.undefine_alias('bar')
    ip.magic('cd -')
    ip.user_ns['_dh'][:] = []
    
    # Check restoring
    ip.magic('store -r')
    nt.assert_equal(ip.user_ns['foo'], 78)
    nt.assert_in('bar', ip.alias_manager.alias_table)
    nt.assert_in(tmpd, ip.user_ns['_dh'])
    
    os.rmdir(tmpd)

## Instruction:
Store magic test. On MacOSX the temp dir in /var is symlinked into /private/var thus making this comparison fail. This is solved by using os.path.realpath to expand the tempdir into is's real directory.
## Code After:
import tempfile, os

import nose.tools as nt

ip = get_ipython()
ip.magic('load_ext storemagic')

def test_store_restore():
    ip.user_ns['foo'] = 78
    ip.magic('alias bar echo "hello"')
    tmpd = tempfile.mkdtemp()
    ip.magic('cd ' + tmpd)
    ip.magic('store foo')
    ip.magic('store bar')
    
    # Check storing
    nt.assert_equal(ip.db['autorestore/foo'], 78)
    nt.assert_in('bar', ip.db['stored_aliases'])
    
    # Remove those items
    ip.user_ns.pop('foo', None)
    ip.alias_manager.undefine_alias('bar')
    ip.magic('cd -')
    ip.user_ns['_dh'][:] = []
    
    # Check restoring
    ip.magic('store -r')
    nt.assert_equal(ip.user_ns['foo'], 78)
    nt.assert_in('bar', ip.alias_manager.alias_table)
    nt.assert_in(os.path.realpath(tmpd), ip.user_ns['_dh'])
    
    os.rmdir(tmpd)
