Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions graphqler/utils/stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

from .file_utils import initialize_file, intialize_file_if_not_exists, recreate_path, get_or_create_file
from .singleton import singleton
import os
import re


@singleton
Expand Down Expand Up @@ -261,6 +263,9 @@
for node_name, results in self.results.items():
# If the node name has slashes, replace them with underscores
node_name = node_name.replace("/", "_")
if os.name == "nt":
# Replace characters that are invalid in Windows filenames
node_name = re.sub(r'[\\/:*?"<>|]', "_", name)

Check failure on line 268 in graphqler/utils/stats.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (F821)

graphqler/utils/stats.py:268:58: F821 Undefined name `name`
for result in results:
result_type = "success" if result.success else "failure"
result_file_path = Path(self.endpoint_results_dir) / node_name / result_type / f"{result.status_code}"
Expand Down
8 changes: 5 additions & 3 deletions tests/integration/test_food_delivery_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from tests.integration.utils.stats import get_percent_query_mutation_success
from tests.integration.utils.run_api import run_node_project, wait_for_server
import os

import shutil

class TestFoodDeliveryAPI(unittest.TestCase):
PORT = 4000
Expand All @@ -18,7 +18,8 @@ class TestFoodDeliveryAPI(unittest.TestCase):
@classmethod
def setUpClass(cls):
# Start the GrapQL server
cls.process = run_node_project(cls.API_PATH, ["node dbinitializer.js"], str(cls.PORT))
node_cmd = shutil.which("node")
cls.process = run_node_project(cls.API_PATH, [f"{node_cmd} dbinitializer.js"], str(cls.PORT))
cls.process_pid = cls.process.pid

# Parse the config
Expand All @@ -33,7 +34,8 @@ def tearDownClass(cls):
if cls.process and cls.process.pid == cls.process_pid:
cls.process.kill()
cls.process.wait()
os.system(f"rm -rf {cls.PATH}")
if os.path.exists(cls.PATH):
shutil.rmtree(cls.PATH)

def test_run_compile_mode_generates_valid_introspection_file(self):
__main__.run_compile_mode(self.PATH, self.URL)
Expand Down
8 changes: 7 additions & 1 deletion tests/integration/test_user_wallet_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
from tests.integration.utils.stats import get_percent_query_mutation_success
from tests.integration.utils.run_api import run_node_project, wait_for_server
import os
import shutil



class TestUserWalletApi(unittest.TestCase):
Expand Down Expand Up @@ -33,7 +35,11 @@
if cls.process and cls.process.pid == cls.process_pid:
cls.process.kill()
cls.process.wait()
os.system(f"rm -rf {cls.PATH}")
if os.path.exists(cls.PATH):
try:
shutil.rmtree(cls.PATH)
except Exception as e:

Check failure on line 41 in tests/integration/test_user_wallet_api.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (F841)

tests/integration/test_user_wallet_api.py:41:33: F841 Local variable `e` is assigned to but never used
pass

def test_run_compile_mode_generates_valid_introspection_file(self):
print(self.PATH, self.URL)
Expand Down
19 changes: 15 additions & 4 deletions tests/integration/utils/run_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import os
import requests
import time
import shutil


def run_node_project(path: str, commands: list[str], port: str) -> subprocess.Popen:
Expand All @@ -18,16 +19,26 @@ def run_node_project(path: str, commands: list[str], port: str) -> subprocess.Po
# Set the environment variable
env = os.environ.copy()
env["PORT"] = port
shell_flag = os.name == "nt" # True no Windows, False no Linux/macOS

# Run npm install
subprocess.run(["npm", "install"], cwd=path, check=True, env=env)
# Run npm install with proper handling
npm_cmd = shutil.which("npm")
node_cmd = shutil.which("node")
if npm_cmd is None:
raise RuntimeError("npm command not found. Please ensure Node.js is installed.")

try:
subprocess.run([npm_cmd, "install"], cwd=path, check=True, env=env, shell=shell_flag)
except subprocess.CalledProcessError as e:
print(f"npm install failed: {e}")
raise

# Run each command in the list
for command in commands:
subprocess.run(command.split(), cwd=path, check=True, env=env)
subprocess.run(command.split(), cwd=path, check=True, env=env, shell=shell_flag)

# Run node server.js
process = subprocess.Popen(["node", "server.js"], cwd=path, env=env)
process = subprocess.Popen([node_cmd, "server.js"], cwd=path, env=env, shell=shell_flag)

return process

Expand Down
Loading