Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PH] Replace usage of os.path with Path and PurePath #571

4 changes: 2 additions & 2 deletions tests/performance_tests/log_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
import gzip
import math

harnessPath = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
sys.path.append(harnessPath)
from pathlib import Path, PurePath
sys.path.append(str(PurePath(PurePath(Path(__file__).absolute()).parent).parent))

from TestHarness import Utils
from dataclasses import dataclass, asdict, field
Expand Down
12 changes: 6 additions & 6 deletions tests/performance_tests/performance_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
import json
import shutil

harnessPath = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
sys.path.append(harnessPath)
from pathlib import Path, PurePath
sys.path.append(str(PurePath(PurePath(Path(__file__).absolute()).parent).parent))

from NodeosPluginArgs import ChainPluginArgs, HttpPluginArgs, NetPluginArgs, ProducerPluginArgs
from TestHarness import TestHelper, Utils
Expand Down Expand Up @@ -79,7 +79,7 @@ class PerfTestSearchResults:

@dataclass
class LoggingConfig:
logDirBase: str = f"./{os.path.splitext(os.path.basename(__file__))[0]}"
logDirBase: str = f"./{PurePath(PurePath(__file__).name).stem[0]}"
logDirTimestamp: str = f"{datetime.utcnow().strftime('%Y-%m-%d_%H-%M-%S')}"
logDirPath: str = field(default_factory=str, init=False)
ptbLogsDirPath: str = field(default_factory=str, init=False)
Expand All @@ -98,7 +98,7 @@ def __init__(self, testHelperConfig: PerformanceTestBasic.TestHelperConfig=Perfo

self.testsStart = datetime.utcnow()

self.loggingConfig = PerformanceTest.LoggingConfig(logDirBase=f"{self.ptConfig.logDirRoot}/{os.path.splitext(os.path.basename(__file__))[0]}",
self.loggingConfig = PerformanceTest.LoggingConfig(logDirBase=f"{self.ptConfig.logDirRoot}/{PurePath(PurePath(__file__).name).stem[0]}",
logDirTimestamp=f"{self.testsStart.strftime('%Y-%m-%d_%H-%M-%S')}")

def performPtbBinarySearch(self, clusterConfig: PerformanceTestBasic.ClusterConfig, logDirRoot: str, delReport: bool, quiet: bool, delPerfLogs: bool) -> TpsTestResult.PerfTestSearchResults:
Expand Down Expand Up @@ -311,7 +311,7 @@ def testDirsCleanup(self):
try:
def removeArtifacts(path):
print(f"Checking if test artifacts dir exists: {path}")
if os.path.isdir(f"{path}"):
if Path(f"{path}").is_dir():
jgiszczak marked this conversation as resolved.
Show resolved Hide resolved
print(f"Cleaning up test artifacts dir and all contents of: {path}")
shutil.rmtree(f"{path}")

Expand All @@ -327,7 +327,7 @@ def testDirsSetup(self):
try:
def createArtifactsDir(path):
print(f"Checking if test artifacts dir exists: {path}")
if not os.path.isdir(f"{path}"):
if not Path(f"{path}").is_dir():
print(f"Creating test artifacts dir: {path}")
os.mkdir(f"{path}")

Expand Down
14 changes: 7 additions & 7 deletions tests/performance_tests/performance_test_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
import log_reader
import launch_transaction_generators as ltg

harnessPath = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
sys.path.append(harnessPath)
from pathlib import Path, PurePath
sys.path.append(str(PurePath(PurePath(Path(__file__).absolute()).parent).parent))

from NodeosPluginArgs import ChainPluginArgs, HttpClientPluginArgs, HttpPluginArgs, NetPluginArgs, ProducerPluginArgs, ResourceMonitorPluginArgs, SignatureProviderPluginArgs, StateHistoryPluginArgs, TraceApiPluginArgs
from TestHarness import Cluster, TestHelper, Utils, WalletMgr
Expand Down Expand Up @@ -100,7 +100,7 @@ def __post_init__(self):

@dataclass
class LoggingConfig:
logDirBase: str = f"./{os.path.splitext(os.path.basename(__file__))[0]}"
logDirBase: str = f"./{PurePath(PurePath(__file__).name).stem[0]}"
logDirTimestamp: str = f"{datetime.utcnow().strftime('%Y-%m-%d_%H-%M-%S')}"
logDirTimestampedOptSuffix: str = ""
logDirPath: str = field(default_factory=str, init=False)
Expand All @@ -121,7 +121,7 @@ def __init__(self, testHelperConfig: TestHelperConfig=TestHelperConfig(), cluste

self.testStart = datetime.utcnow()

self.loggingConfig = PerformanceTestBasic.LoggingConfig(logDirBase=f"{self.ptbConfig.logDirRoot}/{os.path.splitext(os.path.basename(__file__))[0]}",
self.loggingConfig = PerformanceTestBasic.LoggingConfig(logDirBase=f"{self.ptbConfig.logDirRoot}/{PurePath(PurePath(__file__).name).stem[0]}",
logDirTimestamp=f"{self.testStart.strftime('%Y-%m-%d_%H-%M-%S')}",
logDirTimestampedOptSuffix = f"-{self.ptbConfig.targetTps}")

Expand Down Expand Up @@ -155,7 +155,7 @@ def testDirsCleanup(self, delReport: bool=False):
try:
def removeArtifacts(path):
print(f"Checking if test artifacts dir exists: {path}")
if os.path.isdir(f"{path}"):
if Path(f"{path}").is_dir():
jgiszczak marked this conversation as resolved.
Show resolved Hide resolved
print(f"Cleaning up test artifacts dir and all contents of: {path}")
shutil.rmtree(f"{path}")

Expand All @@ -177,7 +177,7 @@ def testDirsSetup(self):
try:
def createArtifactsDir(path):
print(f"Checking if test artifacts dir exists: {path}")
if not os.path.isdir(f"{path}"):
if not Path(f"{path}").is_dir():
jgiszczak marked this conversation as resolved.
Show resolved Hide resolved
print(f"Creating test artifacts dir: {path}")
os.mkdir(f"{path}")

Expand All @@ -194,7 +194,7 @@ def createArtifactsDir(path):
print(error)

def fileOpenMode(self, filePath) -> str:
if os.path.exists(filePath):
if Path(filePath).exists():
jgiszczak marked this conversation as resolved.
Show resolved Hide resolved
append_write = 'a'
else:
append_write = 'w'
Expand Down