| 47 | }; |
| 48 | |
| 49 | TEST_P(TestPythonPlugin, PythonPlugin) { |
| 50 | using namespace lgraph; |
| 51 | using namespace python_plugin; |
| 52 | std::string plugin_dir = "./python_plugin"; |
| 53 | size_t n_workers = 2, n_jobs = 3; |
| 54 | n_workers = GetParam().j; |
| 55 | n_jobs = GetParam().n; |
| 56 | int argc = _ut_argc; |
| 57 | char** argv = _ut_argv; |
| 58 | Configuration config; |
| 59 | config.Add(plugin_dir, "d,dir", true).Comment("Directory where plugin files are stored."); |
| 60 | config.Add(n_workers, "j,workers", true).Comment("Number of Python worker threads to use."); |
| 61 | config.Add(n_jobs, "n,jobs", true).Comment("Number of Python jobs."); |
| 62 | config.ParseAndFinalize(argc, argv); |
| 63 | const char* sleep_plugin = "./sleep.py"; |
| 64 | const char* read_plugin = "./scan_graph.py"; |
| 65 | const char* write_plugin = "./write_vertex.py"; |
| 66 | std::string code_sleep; |
| 67 | std::string code_read; |
| 68 | std::string code_write; |
| 69 | { |
| 70 | UT_LOG() << "Create test files"; |
| 71 | code_sleep = R"( |
| 72 | import time |
| 73 | def Process(db, input): |
| 74 | t = 1 |
| 75 | try: |
| 76 | t = int(input) |
| 77 | except: |
| 78 | return (False, 'input must be a time duration') |
| 79 | print('sleeping for {} seconds'.format(t)) |
| 80 | time.sleep(t) |
| 81 | return (True, '') |
| 82 | )"; |
| 83 | code_read = R"( |
| 84 | def Process(db, input): |
| 85 | n = 0 |
| 86 | try: |
| 87 | n = int(input) |
| 88 | except: |
| 89 | pass |
| 90 | if n == 0: |
| 91 | n = 1000000 |
| 92 | txn = db.CreateReadTxn() |
| 93 | it = txn.GetVertexIterator() |
| 94 | nv = 0 |
| 95 | while it.IsValid() and nv < n: |
| 96 | nv = nv + 1 |
| 97 | it.Next() |
| 98 | return (True, str(nv)) |
| 99 | )"; |
| 100 | code_write = R"( |
| 101 | from liblgraph_python_api import * |
| 102 | def Process(db, input): |
| 103 | db.AddVertexLabel("v", [FieldSpec("id",FieldType.INT32,False),FieldSpec("name",FieldType.STRING,True)]) |
| 104 | txn = db.CreateWriteTxn() |
| 105 | id = txn.AddVertex("v", {"id":1, "name":"001"}) |
| 106 | txn.Commit() |
nothing calls this directly
no test coverage detected