|
8 | 8 |
|
9 | 9 | DATA_PATH = Path(__file__).parent / "data" |
10 | 10 |
|
11 | | -NOT_GTHUB_ACTIONS = True |
12 | | -if os.getenv("GITHUB_ACTIONS") == "true": |
13 | | - NOT_GTHUB_ACTIONS = False |
14 | | - |
15 | | - |
16 | | -@pytest.mark.skipif(NOT_GTHUB_ACTIONS, reason="Not running via GitHub Actions") |
17 | | -class TestCli: |
18 | | - """Testing OpenSearch database CLI integration.""" |
19 | | - |
20 | | - @pytest.fixture(autouse=True) |
21 | | - def abcd(self): |
22 | | - """Set up OpenSearch database connection and login with CLI.""" |
23 | | - security_enabled = os.getenv("security_enabled") == "true" |
24 | | - port = int(os.environ["port"]) |
25 | | - host = "localhost" |
26 | | - if os.environ["opensearch-version"] == "latest": |
27 | | - credential = "admin:myStrongPassword123!" |
28 | | - else: |
29 | | - credential = "admin:admin" |
30 | | - |
31 | | - logging.basicConfig(level=logging.INFO) |
32 | | - |
33 | | - url = f"opensearch://{credential}@{host}:{port}" |
34 | | - if not security_enabled: |
35 | | - url += " --disable_ssl" |
36 | | - try: |
37 | | - subprocess.run(f"abcd login {url}", shell=True, check=True) |
38 | | - except subprocess.CalledProcessError: |
39 | | - sleep(10) |
40 | | - subprocess.run(f"abcd login {url}", shell=True, check=True) |
41 | | - |
42 | | - def test_summary(self, abcd): |
43 | | - """ |
44 | | - Test summary output of uploaded data file. |
45 | | - """ |
46 | | - data_file = DATA_PATH / "example.xyz" |
47 | | - |
48 | | - subprocess.run( |
49 | | - f"abcd upload {data_file} -i -e 'test_data'", shell=True, check=True |
50 | | - ) |
51 | | - subprocess.run("abcd refresh", shell=True, check=True) |
52 | | - |
53 | | - summary = subprocess.run( |
54 | | - "abcd summary", shell=True, check=True, capture_output=True, text=True |
55 | | - ) |
56 | | - assert "Total number of configurations" in summary.stdout |
57 | | - subprocess.run("abcd delete -q 'test_data' -y", shell=True) |
58 | | - |
59 | | - def test_query(self, abcd): |
60 | | - """ |
61 | | - Test lucene-style query. |
62 | | - """ |
63 | | - data_file_1 = DATA_PATH / "example.xyz" |
64 | | - data_file_2 = DATA_PATH / "example_2.xyz" |
65 | | - |
66 | | - subprocess.run( |
67 | | - f"abcd upload {data_file_1} -i -e 'test_data'", shell=True, check=True |
68 | | - ) |
69 | | - subprocess.run( |
70 | | - f"abcd upload {data_file_2} -i -e 'test_data'", shell=True, check=True |
71 | | - ) |
72 | | - subprocess.run("abcd refresh", shell=True, check=True) |
73 | | - |
74 | | - summary = subprocess.run( |
75 | | - "abcd show -p n_atoms -q 'n_atoms : 2'", |
76 | | - shell=True, |
77 | | - check=True, |
78 | | - capture_output=True, |
79 | | - text=True, |
80 | | - ) |
81 | | - assert "2" in summary.stdout and "3" not in summary.stdout |
82 | | - summary = subprocess.run( |
83 | | - "abcd show -p n_atoms -q 'n_atoms : 3'", |
84 | | - shell=True, |
85 | | - check=True, |
86 | | - capture_output=True, |
87 | | - text=True, |
88 | | - ) |
89 | | - assert "3" in summary.stdout and "2" not in summary.stdout |
90 | | - subprocess.run("abcd delete -q 'test_data' -y", shell=True) |
91 | | - |
92 | | - def test_range_query(self, abcd): |
93 | | - """ |
94 | | - Test lucene-style ranged query. |
95 | | - """ |
96 | | - data_file_1 = DATA_PATH / "example.xyz" |
97 | | - data_file_2 = DATA_PATH / "example_2.xyz" |
98 | | - |
99 | | - subprocess.run( |
100 | | - f"abcd upload {data_file_1} -i -e 'test_data'", shell=True, check=True |
101 | | - ) |
102 | | - subprocess.run( |
103 | | - f"abcd upload {data_file_2} -i -e 'test_data'", shell=True, check=True |
104 | | - ) |
105 | | - subprocess.run("abcd refresh", shell=True, check=True) |
106 | | - |
107 | | - summary = subprocess.run( |
108 | | - "abcd summary -p energy -q 'energy:[-100 TO -99]'", |
109 | | - shell=True, |
110 | | - check=True, |
111 | | - capture_output=True, |
112 | | - text=True, |
113 | | - ) |
114 | | - assert "Total number of configurations: 1" in summary.stdout |
115 | | - |
116 | | - summary = subprocess.run( |
117 | | - "abcd summary -p energy -q 'energy:[-102 TO -99]'", |
118 | | - shell=True, |
119 | | - check=True, |
120 | | - capture_output=True, |
121 | | - text=True, |
122 | | - ) |
123 | | - assert "Total number of configurations: 2" in summary.stdout |
124 | | - subprocess.run("abcd delete -q 'test_data' -y", shell=True) |
| 11 | +PORT = int(os.environ.get("port", 0)) |
| 12 | +HOST = "localhost" |
| 13 | +CREDENTIAL = "admin:myStrongPassword_123" |
| 14 | +SECURITY_ENABLED = os.getenv("security_enabled") == "true" |
| 15 | + |
| 16 | + |
| 17 | +@pytest.fixture(autouse=True) |
| 18 | +def skip_if_not_github_actions(): |
| 19 | + if os.getenv("GITHUB_ACTIONS") == "true": |
| 20 | + yield |
| 21 | + pytest.skip("Not running via GitHub Actions") |
| 22 | + |
| 23 | + |
| 24 | +@pytest.fixture(autouse=True) |
| 25 | +def abcd(): |
| 26 | + """Set up OpenSearch database connection and login with CLI.""" |
| 27 | + logging.basicConfig(level=logging.INFO) |
| 28 | + |
| 29 | + url = f"opensearch://{CREDENTIAL}@{HOST}:{PORT}" |
| 30 | + if not SECURITY_ENABLED: |
| 31 | + url += " --disable_ssl" |
| 32 | + try: |
| 33 | + subprocess.run(f"abcd login {url}", shell=True, check=True) |
| 34 | + except subprocess.CalledProcessError: |
| 35 | + sleep(10) |
| 36 | + subprocess.run(f"abcd login {url}", shell=True, check=True) |
| 37 | + |
| 38 | + |
| 39 | +def test_summary(): |
| 40 | + """Test summary output of uploaded data file.""" |
| 41 | + data_file = DATA_PATH / "example.xyz" |
| 42 | + |
| 43 | + subprocess.run(f"abcd upload {data_file} -i -e 'test_data'", shell=True, check=True) |
| 44 | + subprocess.run("abcd refresh", shell=True, check=True) |
| 45 | + |
| 46 | + summary = subprocess.run( |
| 47 | + "abcd summary", shell=True, check=True, capture_output=True, text=True |
| 48 | + ) |
| 49 | + assert "Total number of configurations" in summary.stdout |
| 50 | + subprocess.run("abcd delete -q 'test_data' -y", shell=True) |
| 51 | + |
| 52 | + |
| 53 | +def test_query(): |
| 54 | + """Test lucene-style query.""" |
| 55 | + data_file_1 = DATA_PATH / "example.xyz" |
| 56 | + data_file_2 = DATA_PATH / "example_2.xyz" |
| 57 | + |
| 58 | + subprocess.run( |
| 59 | + f"abcd upload {data_file_1} -i -e 'test_data'", shell=True, check=True |
| 60 | + ) |
| 61 | + subprocess.run( |
| 62 | + f"abcd upload {data_file_2} -i -e 'test_data'", shell=True, check=True |
| 63 | + ) |
| 64 | + subprocess.run("abcd refresh", shell=True, check=True) |
| 65 | + |
| 66 | + summary = subprocess.run( |
| 67 | + "abcd show -p n_atoms -q 'n_atoms : 2'", |
| 68 | + shell=True, |
| 69 | + check=True, |
| 70 | + capture_output=True, |
| 71 | + text=True, |
| 72 | + ) |
| 73 | + assert "2" in summary.stdout and "3" not in summary.stdout |
| 74 | + summary = subprocess.run( |
| 75 | + "abcd show -p n_atoms -q 'n_atoms : 3'", |
| 76 | + shell=True, |
| 77 | + check=True, |
| 78 | + capture_output=True, |
| 79 | + text=True, |
| 80 | + ) |
| 81 | + assert "3" in summary.stdout and "2" not in summary.stdout |
| 82 | + subprocess.run("abcd delete -q 'test_data' -y", shell=True) |
| 83 | + |
| 84 | + |
| 85 | +def test_range_query(): |
| 86 | + """Test lucene-style ranged query.""" |
| 87 | + data_file_1 = DATA_PATH / "example.xyz" |
| 88 | + data_file_2 = DATA_PATH / "example_2.xyz" |
| 89 | + |
| 90 | + subprocess.run(f"abcd upload {data_file_1} -e 'test_data'", shell=True, check=True) |
| 91 | + subprocess.run(f"abcd upload {data_file_2} -e 'test_data'", shell=True, check=True) |
| 92 | + subprocess.run("abcd refresh", shell=True, check=True) |
| 93 | + |
| 94 | + summary = subprocess.run( |
| 95 | + "abcd summary -p energy -q 'energy:[-100 TO -99]'", |
| 96 | + shell=True, |
| 97 | + check=True, |
| 98 | + capture_output=True, |
| 99 | + text=True, |
| 100 | + ) |
| 101 | + assert "Total number of configurations: 1" in summary.stdout |
| 102 | + |
| 103 | + summary = subprocess.run( |
| 104 | + "abcd summary -p energy -q 'energy:[-102 TO -99]'", |
| 105 | + shell=True, |
| 106 | + check=True, |
| 107 | + capture_output=True, |
| 108 | + text=True, |
| 109 | + ) |
| 110 | + assert "Total number of configurations: 2" in summary.stdout |
| 111 | + subprocess.run("abcd delete -q 'test_data' -y", shell=True) |
0 commit comments