def test_file_amend():
    '%%writefile -a amends files'
    ip = get_ipython()
    with TemporaryDirectory() as td:
        fname = os.path.join(td, 'file2')
        ip.run_cell_magic('writefile', fname, u'\n'.join(['line1', 'line2']))
        ip.run_cell_magic('writefile', ('-a %s' % fname), u'\n'.join(['line3', 'line4']))
        with open(fname) as f:
            s = f.read()
        nt.assert_in('line1\n', s)
        nt.assert_in('line3\n', s)
%%writefile -a amends files
def test_file_amend():
    
    ip = get_ipython()
    with TemporaryDirectory() as td:
        fname = os.path.join(td, 'file2')
        ip.run_cell_magic('writefile', fname, u'\n'.join(['line1', 'line2']))
        ip.run_cell_magic('writefile', ('-a %s' % fname), u'\n'.join(['line3', 'line4']))
        with open(fname) as f:
            s = f.read()
        nt.assert_in('line1\n', s)
        nt.assert_in('line3\n', s)