@@ -0,0 +1,1906 @@
+import os.path%0A%0Afrom homely._test import contents, run_update_all%0A%0A%0Adef test_files_writefile(HOME, testrepo):%0A    contents(%0A        testrepo.remotepath + '/HOMELY.py',%0A        %22%22%22%0A        import json%0A        from homely.files import mkdir, writefile%0A%0A        mkdir('~/somedir')%0A        with writefile('~/somedir/somefile.txt') as f:%0A            json.dump(%7B'one': 1*1%7D, f)%0A        %22%22%22%0A    )%0A%0A    # pull first so we get the new HOMELY.py script%0A    run_update_all(pullfirst=True)%0A    assert contents(HOME + '/somedir/somefile.txt') == '%7B%22one%22: 1%7D'%0A%0A%0Adef test_files_writefile_cleans_up_or_not(testrepo, HOME):%0A    # create file A.txt already%0A    contents(HOME + '/A.txt', 'before-update')%0A%0A    contents(%0A        testrepo.remotepath + '/HOMELY.py',%0A        %22%22%22%0A        from homely.files import writefile%0A%0A        with writefile('~/A.txt') as f1:%0A            f1.write('AAA%5C%5Cn')%0A        with writefile('~/B.txt') as f2:%0A            f2.write('BBB%5C%5Cn')%0A        with writefile('~/C.txt') as f3:%0A            f3.write('CCC%5C%5Cn')%0A        %22%22%22%0A    )%0A%0A    # pull first so we get the new HOMELY.py script%0A    run_update_all(pullfirst=True, cancleanup=True)%0A    assert contents(HOME + '/A.txt') == 'AAA%5Cn'%0A    assert contents(HOME + '/B.txt') == 'BBB%5Cn'%0A    assert contents(HOME + '/C.txt') == 'CCC%5Cn'%0A%0A    # now remove the writes to A.txt and B.txt%0A    contents(%0A        testrepo.remotepath + '/HOMELY.py',%0A        %22%22%22%0A        from homely.files import writefile%0A%0A        with writefile('~/C.txt') as f3:%0A            f3.write('CCC FINAL%5C%5Cn')%0A        %22%22%22%0A    )%0A    run_update_all(pullfirst=True, cancleanup=True)%0A%0A    # A.txt is *not* cleaned up because it wasn't created by homely%0A    assert contents(HOME + '/A.txt') == 'AAA%5Cn'%0A%0A    # B.txt *is* cleaned up because homely creatd it%0A    assert not os.path.exists(HOME + '/B.txt')%0A%0A    # C.txt is modified to final state%0A    assert contents(HOME + '/C.txt') == 'CCC FINAL%5Cn'%0A

Add tests for writefile()