Skip to content

Commit

Permalink
Docstring updates
Browse files Browse the repository at this point in the history
  • Loading branch information
djperrefort committed Aug 20, 2024
1 parent b4d5bd4 commit 137cea2
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 30 deletions.
8 changes: 4 additions & 4 deletions apps/crc_sinfo.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""A simple wrapper around the Slurm ``sinfo`` command.
"""A simple wrapper around the Slurm `sinfo` command.
This application is equivalent to running:
Expand All @@ -17,7 +17,7 @@ class CrcSinfo(BaseParser):
"""Display information about available Slurm clusters."""

def __init__(self) -> None:
"""Define the application commandline interface"""
"""Define the application commandline interface."""

super().__init__()
self.add_argument('-c', '--cluster', nargs='?', default='all', help='only show jobs for the given cluster')
Expand All @@ -26,10 +26,10 @@ def __init__(self) -> None:
help='print the equivalent slurm command and exit')

def app_logic(self, args: Namespace) -> None:
"""Logic to evaluate when executing the application
"""Logic to evaluate when executing the application.
Args:
args: Parsed command line arguments
args: Parsed command line arguments.
"""

command = f'sinfo -M {args.cluster}'
Expand Down
12 changes: 6 additions & 6 deletions apps/crc_squeue.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""A simple wrapper around the Slurm ``squeue`` command."""
"""A simple wrapper around the Slurm `squeue` command."""

import getpass
from argparse import Namespace
Expand All @@ -16,7 +16,7 @@ class CrcSqueue(BaseParser):
output_format_all = "-o '%.8i %.3P %.6a %.6u %.35j %.2t %.12M %.6D %.4C %.50R %.20S'"

def __init__(self) -> None:
"""Define the application commandline interface"""
"""Define the application commandline interface."""

super(CrcSqueue, self).__init__()
self.add_argument('-a', '--all', action='store_true', help='show all jobs (defaults to current user only)')
Expand All @@ -27,10 +27,10 @@ def __init__(self) -> None:

@classmethod
def build_slurm_command(cls, args: Namespace) -> str:
"""Return an ``squeue`` command matching parsed command line arguments
"""Return an `squeue` command matching parsed command line arguments.
Args:
args: Parsed command line arguments
args: Parsed command line arguments.
"""

# Build the base command
Expand All @@ -47,10 +47,10 @@ def build_slurm_command(cls, args: Namespace) -> str:
return ' '.join(command_options)

def app_logic(self, args: Namespace) -> None:
"""Logic to evaluate when executing the application
"""Logic to evaluate when executing the application.
Args:
args: Parsed command line arguments
args: Parsed command line arguments.
"""

command = self.build_slurm_command(args)
Expand Down
10 changes: 5 additions & 5 deletions tests/test_crc_sinfo.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Tests for the ``CrcSinfo`` class."""
"""Tests for the `CrcSinfo` class."""

from io import StringIO
from unittest import TestCase
Expand All @@ -8,18 +8,18 @@


class CommandExecution(TestCase):
"""Test the execution/printing of Slurm commands"""
"""Test the execution/printing of Slurm commands."""

@patch('apps.utils.system_info.Shell.run_command')
def test_all_clusters(self, mock_shell: Mock) -> None:
"""Test all clusters are included in the slurm command by default"""
"""Test all clusters are included in the slurm command by default."""

CrcSinfo().execute([])
mock_shell.assert_called_with('sinfo -M all')

@patch('apps.utils.system_info.Shell.run_command')
def test_custom_cluster(self, mock_shell: Mock) -> None:
"""Test the ``--cluster`` argument is passed to Slurm"""
"""Test the `--cluster` argument is passed to Slurm."""

CrcSinfo().execute(['-c', 'mpi'])
mock_shell.assert_called_with('sinfo -M mpi')
Expand All @@ -30,7 +30,7 @@ def test_custom_cluster(self, mock_shell: Mock) -> None:
@patch('sys.stdout', new_callable=StringIO)
@patch('apps.utils.system_info.Shell.run_command')
def test_command_is_printed(self, mock_shell: Mock, mock_stdout: Mock) -> None:
"""Test the ``slurm`` command is printed but not executed when ``-z`` is specified"""
"""Test the `slurm` command is printed but not executed when `-z` is specified."""

CrcSinfo().execute(['-z'])
self.assertEqual('sinfo -M all', mock_stdout.getvalue().strip())
Expand Down
30 changes: 15 additions & 15 deletions tests/test_crc_squeue.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Tests for the ``crc-squeue`` application."""
"""Tests for the `crc-squeue` application."""

import getpass
from io import StringIO
Expand All @@ -12,21 +12,21 @@ class ArgumentParsing(TestCase):
"""Test the parsing of command line arguments"""

def test_default_arguments_are_false(self) -> None:
"""Test default values for all flag arguments are ``False``"""
"""Test default values for all flag arguments are `False`."""

args, _ = CrcSqueue().parse_known_args([])
self.assertFalse(args.all)
self.assertFalse(args.watch)
self.assertFalse(args.print_command)

def test_defaults_to_all_clusters(self) -> None:
"""Test the cluster argument defaults to ``all`` clusters"""
"""Test the cluster argument defaults to `all` clusters."""

args, _ = CrcSqueue().parse_known_args([])
self.assertEqual('all', args.cluster)

def test_custom_clusters(self) -> None:
"""Test the custom cluster names are stored by the parser"""
"""Test the custom cluster names are stored by the parser."""

app = CrcSqueue()
args, _ = app.parse_known_args(['-c', 'smp'])
Expand All @@ -36,7 +36,7 @@ def test_custom_clusters(self) -> None:
self.assertEqual('smp', args.cluster)

def test_watch_argument_stores_const(self) -> None:
"""Test the ``--watch`` argument stores the update interval as an integer"""
"""Test the `--watch` argument stores the update interval as an integer."""

app = CrcSqueue()
args, _ = app.parse_known_args(['--w'])
Expand All @@ -47,10 +47,10 @@ def test_watch_argument_stores_const(self) -> None:


class SlurmCommandCreation(TestCase):
"""Test the creation of ``squeue`` commands based on command line arguments"""
"""Test the creation of `squeue` commands based on command line arguments."""

def test_user_option(self) -> None:
"""Test the ``--all`` argument toggles the slurm ``-u`` option in the returned command"""
"""Test the `--all` argument toggles the slurm `-u` option in the returned command."""

app = CrcSqueue()
slurm_user_argument = f'-u {getpass.getuser()}'
Expand All @@ -60,13 +60,13 @@ def test_user_option(self) -> None:
slurm_command = app.build_slurm_command(args)
self.assertIn(slurm_user_argument, slurm_command, '-u flag is missing from slurm command')

# Make sure user option is disabled when ``--all`` argument is given
# Make sure user option is disabled when `--all` argument is given
args, _ = app.parse_known_args(['--all'])
slurm_command = app.build_slurm_command(args)
self.assertNotIn(slurm_user_argument, slurm_command, '-u flag was added to slurm command')

def test_cluster_name(self) -> None:
"""Test the generated slurm command specifies the correct cluster"""
"""Test the generated slurm command specifies the correct cluster."""

app = CrcSqueue()

Expand All @@ -80,31 +80,31 @@ def test_cluster_name(self) -> None:


class OutputFormat(TestCase):
"""Test the correct output format is specified in the piped slurm command"""
"""Test the correct output format is specified in the piped slurm command."""

@patch('apps.utils.system_info.Shell.run_command')
def test_defaults_to_user_format(self, mock_shell: Mock) -> None:
"""Test the application defaults to using the ``output_format_user`` format"""
"""Test the application defaults to using the `output_format_user` format."""

CrcSqueue().execute([])
executed_command = mock_shell.call_args.args[0]
self.assertIn(CrcSqueue.output_format_user, executed_command)

@patch('apps.utils.system_info.Shell.run_command')
def test_all_flag(self, mock_shell: Mock) -> None:
"""Test the application defaults to using the ``output_format_all`` format"""
"""Test the application defaults to using the `output_format_all` format."""

CrcSqueue().execute(['--all'])
executed_command = mock_shell.call_args.args[0]
self.assertIn(CrcSqueue.output_format_all, executed_command)


class CommandExecution(TestCase):
"""Test the execution of Slurm commands"""
"""Test the execution of Slurm commands."""

@patch('apps.utils.system_info.Shell.run_command')
def test_slurm_command_executed(self, mock_shell: Mock) -> None:
"""Test the slurm command is executed by the application"""
"""Test the slurm command is executed by the application."""

# Parse commandline arguments and generate the expected slurm command
app = CrcSqueue()
Expand All @@ -117,7 +117,7 @@ def test_slurm_command_executed(self, mock_shell: Mock) -> None:
@patch('sys.stdout', new_callable=StringIO)
@patch('apps.utils.system_info.Shell.run_command')
def test_slurm_command_printed(self, mock_shell: Mock, mock_stdout: Mock) -> None:
"""Test the slurm command is printed but not executed when ``-z`` is specified"""
"""Test the slurm command is printed but not executed when `-z` is specified."""

app = CrcSqueue()

Expand Down

0 comments on commit 137cea2

Please sign in to comment.