コード例 #1
0
ファイル: test_sync.py プロジェクト: causalitygroup/causync
def test_sync():
    create_temp()

    # start sync testing
    cs = CauSync(config, src, dst, task='sync')
    cs.config.DATE_FORMAT = date_format
    cs.run_sync()

    # check for test dirs
    [
        assert_true(
            os.path.isdir(os.path.join(dst, curdate_str, 'causync_src', d)))
        for d in ['testdir1', 'testdir2']
    ]

    # collect destination testfile paths
    files = [
        os.path.join(dst, curdate_str, 'causync_src', 'testdir1', 'testfile1'),
        os.path.join(dst, curdate_str, 'causync_src', 'testdir1', 'testfile2'),
        os.path.join(dst, curdate_str, 'causync_src', 'testdir2', 'testfile3')
    ]

    # check for existing testfiles
    [assert_true(os.path.isfile(f)) for f in files]

    # compare testfile contents
    for i in range(0, 3):
        with open(files[i], 'r') as fp:
            assert_equals(fp.read(),
                          lorem[lorem_parts[i][0]:lorem_parts[i][1]])

    remove_temp()
コード例 #2
0
ファイル: test_sync.py プロジェクト: causalitygroup/causync
def test_dry_run():
    create_temp()

    # start sync testing
    cs = CauSync(config, src, dst, task='sync')
    cs.config.DATE_FORMAT = date_format
    cs.dry_run = True
    cs.run_sync()

    # check for non-existing test dirs
    [
        assert_false(
            os.path.isdir(os.path.join(dst, curdate_str, 'causync_src', d)))
        for d in ['testdir1', 'testdir2']
    ]

    # collect destination testfile paths
    files = [
        os.path.join(dst, curdate_str, 'causync_src', 'testdir1', 'testfile1'),
        os.path.join(dst, curdate_str, 'causync_src', 'testdir1', 'testfile2'),
        os.path.join(dst, curdate_str, 'causync_src', 'testdir2', 'testfile3')
    ]

    # check for non-existing testfiles
    [assert_false(os.path.isfile(f)) for f in files]

    remove_temp()
コード例 #3
0
def test_exclude_file():
    create_temp()

    with open('./temp/exclude.txt', 'w') as f:
        f.write('testfile1\ntestfile3\n')

    # start sync testing
    cs = CauSync(config, src, dst, task='sync')
    cs.config.DATE_FORMAT = date_format
    cs.excludes = cs.parse_exclude_file('./temp/exclude.txt')
    cs.run_sync()

    # collect destination testfile paths
    files = [
        os.path.join(dst, curdate_str, 'causync_src', 'testdir1', 'testfile1'),
        os.path.join(dst, curdate_str, 'causync_src', 'testdir1', 'testfile2'),
        os.path.join(dst, curdate_str, 'causync_src', 'testdir2', 'testfile3')
    ]

    # check for file1 and file3
    [assert_false(os.path.isfile(f)) for f in [files[0], files[2]]]
    # file2 should not exist because of exclude
    assert_true(os.path.isfile(files[1]))

    remove_temp()
コード例 #4
0
def test_multi_exclude():
    create_temp()

    # start sync testing
    cs = CauSync(config,
                 src,
                 dst,
                 task='sync',
                 excludes=['testfile2', 'testfile3'])
    cs.config.DATE_FORMAT = date_format
    cs.run_sync()

    # collect destination testfile paths
    files = [
        os.path.join(dst, curdate_str, 'causync_src', 'testdir1', 'testfile1'),
        os.path.join(dst, curdate_str, 'causync_src', 'testdir1', 'testfile2'),
        os.path.join(dst, curdate_str, 'causync_src', 'testdir2', 'testfile3')
    ]

    # check for file1 and file4
    assert_true(os.path.isfile(files[0]))
    # file2 and file3 should not exist because of exclude
    [assert_false(os.path.isfile(f)) for f in [files[1], files[2]]]

    remove_temp()
コード例 #5
0
ファイル: test_sync.py プロジェクト: causalitygroup/causync
def test_lockfile_after_sync():
    create_temp()

    # start sync testing
    cs = CauSync(config, src, dst, task='sync')
    cs.config.DATE_FORMAT = date_format
    cs.run_sync()

    # lockfile should not exist after sync
    assert_false(os.path.isfile("{}.lock".format(src)))

    remove_temp()
コード例 #6
0
def test_logfile_default():
    create_temp()

    # start sync testing
    cs = CauSync(config, src, dst, task='sync')
    cs.config.DATE_FORMAT = date_format
    cs.run_sync()

    # lockfile should not exist after sync
    assert_true(os.path.isfile(cs.config.LOGFILE))

    remove_temp()
コード例 #7
0
def test_logfile_custom():
    create_temp()

    # start sync testing
    cs = CauSync(config, src, dst, task='sync', logfile='./temp/test.log')
    cs.config.DATE_FORMAT = date_format
    cs.run_sync()

    # lockfile should not exist after sync
    assert_true(os.path.isfile('./temp/test.log'))

    remove_temp()