Skip to content

Commit c5d30b3

Browse files
Modifying unit tests
Linting Changed the name of the profiler module.
1 parent a09bf32 commit c5d30b3

File tree

3 files changed

+10
-191
lines changed

3 files changed

+10
-191
lines changed

cylc/flow/scripts/profile.py

Lines changed: 0 additions & 177 deletions
This file was deleted.

cylc/flow/scripts/profiler.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
import sys
2626
import time
2727
import signal
28-
import subprocess
2928
from pathlib import Path
3029
from dataclasses import dataclass
3130
from cylc.flow.terminal import cli_function
@@ -36,6 +35,7 @@
3635
RE_INT = re.compile(r'\d+')
3736

3837

38+
3939
def get_option_parser() -> COP:
4040
parser = COP(
4141
__doc__,
@@ -116,11 +116,9 @@ def get_cgroup_dir():
116116
# Get the PID of the current process
117117
pid = os.getpid()
118118
# Get the cgroup information for the current process
119-
result = subprocess.run(['cat', '/proc/' + str(pid) + '/cgroup'],
120-
capture_output=True, text=True, shell=False)
121-
if result.stderr:
122-
print(result.stderr, file=sys.stderr)
123-
result = PID_REGEX.search(result.stdout).group()
119+
with open('/proc/' + str(pid) + '/cgroup', 'r') as f:
120+
result = f.read()
121+
result = PID_REGEX.search(result).group()
124122
return result
125123

126124

@@ -154,7 +152,6 @@ def profile(args):
154152
print(err)
155153
raise FileNotFoundError("cgroups not found:"
156154
+ args.cgroup_location) from err
157-
158155
elif cgroup_version == 2:
159156
try:
160157
processes.append(Process(
@@ -191,4 +188,4 @@ def profile(args):
191188
if __name__ == "__main__":
192189

193190
arg_parser = get_option_parser()
194-
profile(arg_parser.parse_args())
191+
profile(arg_parser.parse_args([]))

tests/unit/test_job_file.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,13 @@ def fixture_get_platform():
6565
Returns:
6666
platforms dictionary.
6767
"""
68+
6869
def inner_func(custom_settings=None):
6970
platform = platform_from_name()
7071
if custom_settings is not None:
7172
platform.update(custom_settings)
7273
return platform
74+
7375
yield inner_func
7476

7577

@@ -159,9 +161,9 @@ def test_write(fixture_get_platform):
159161
"execution_time_limit": 60
160162
},
161163
('\n\n# DIRECTIVES:\n# @ job_name = farm_noises.baa.1'
162-
'\n# @ output = directory/job.out\n# @ error = directory/'
163-
'job.err\n# @ wall_clock_limit = 120,60\n# @ moo = foo'
164-
'\n# @ cluck = bar\n# @ queue')
164+
'\n# @ output = directory/job.out\n# @ error = directory/'
165+
'job.err\n# @ wall_clock_limit = 120,60\n# @ moo = foo'
166+
'\n# @ cluck = bar\n# @ queue')
165167
166168
),
167169
( # Check no directives is correctly written
@@ -217,7 +219,6 @@ def test_write(fixture_get_platform):
217219
"job_d": "1/test_task_id/01",
218220
"job_file_path": "$HOME/directory/job",
219221
"execution_time_limit": 1000
220-
221222
},
222223
('\n\n# DIRECTIVES:\n#$ -N farm_noises.baa.1\n#$ -o directory/'
223224
'job.out\n#$ -e directory/job.err\n#$ -l h_rt=0:16:40\n#$ -V\n#'
@@ -383,7 +384,6 @@ def test_no_script_section_with_comment_only_script():
383384
}
384385

385386
with io.StringIO() as fake_file:
386-
387387
JobFileWriter()._write_script(fake_file, job_conf)
388388
blah = fake_file.getvalue()
389389
print(blah)
@@ -539,4 +539,3 @@ def test_homeless_platform(fixture_get_platform):
539539
job_sh_txt = job_sh.read()
540540
if 'HOME' in job_sh_txt:
541541
raise Exception('$HOME found in job.sh\n{job_sh_txt}')
542-

0 commit comments

Comments
 (0)