memgraph/tools/tests/test_mg_import_csv

44 lines
1.7 KiB
Plaintext
Raw Normal View History

#!/usr/bin/env python3
'''Run mg_import_csv and test that recovery works with mg_recovery_check.'''
import argparse
import subprocess
import os
import tempfile
_SCRIPT_DIR = os.path.dirname(os.path.realpath(__file__))
def parse_args():
argp = argparse.ArgumentParser(description=__doc__)
argp.add_argument('--mg-import-csv', required=True,
help='Path to mg_import_csv executable.')
argp.add_argument('--mg-recovery-check', required=True,
help='Path to mg_recovery_check executable.')
return argp.parse_args()
def main():
args = parse_args()
comment_nodes = os.path.join(_SCRIPT_DIR, 'csv', 'comment_nodes.csv')
forum_nodes = os.path.join(_SCRIPT_DIR, 'csv', 'forum_nodes.csv')
relationships_0 = os.path.join(_SCRIPT_DIR, 'csv', 'relationships_0.csv')
relationships_1 = os.path.join(_SCRIPT_DIR, 'csv', 'relationships_1.csv')
with tempfile.TemporaryDirectory(
suffix='-durability', dir=_SCRIPT_DIR) as durability_dir:
snapshot_dir = os.path.join(durability_dir, 'snapshots')
os.makedirs(snapshot_dir, exist_ok=True)
out_snapshot = os.path.join(snapshot_dir, 'snapshot')
mg_import_csv = [args.mg_import_csv, '--nodes', comment_nodes,
'--nodes', forum_nodes, '--relationships', relationships_0,
'--relationships', relationships_1,
'--out', out_snapshot, '--csv-delimiter=|', '--array-delimiter=;']
subprocess.check_call(mg_import_csv)
mg_recovery_check = [args.mg_recovery_check, '--durability-dir', durability_dir]
subprocess.check_call(mg_recovery_check)
if __name__ == '__main__':
main()