-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
61 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,16 @@ | ||
# -*- coding: utf-8 -*- | ||
import unittest | ||
|
||
from smartdispatch import utils | ||
|
||
try: | ||
from mock import patch | ||
import mock | ||
except ImportError: | ||
from unittest.mock import patch | ||
import unittest.mock | ||
This comment has been minimized.
Sorry, something went wrong. |
||
from nose.tools import assert_equal, assert_true | ||
from numpy.testing import assert_array_equal | ||
import subprocess | ||
|
||
from smartdispatch import utils | ||
|
||
class PrintBoxedTests(unittest.TestCase): | ||
|
||
|
@@ -49,3 +54,40 @@ def test_slugify(): | |
|
||
for arg, expected in testing_arguments: | ||
assert_equal(utils.slugify(arg), expected) | ||
|
||
command_output = """\ | ||
Server Max Tot Que Run Hld Wat Trn Ext Com Status | ||
---------------- --- --- --- --- --- --- --- --- --- ---------- | ||
gpu-srv1.{} 0 1674 524 121 47 0 0 22 960 Idle | ||
""" | ||
|
||
slurm_command = """\ | ||
Cluster ControlHost ControlPort RPC Share GrpJobs GrpTRES GrpSubmit MaxJobs MaxTRES MaxSubmit MaxWall QOS Def QOS | ||
---------- --------------- ------------ ----- --------- ------- ------------- --------- ------- ------------- --------- ----------- -------------------- --------- | ||
{} 132.204.24.224 6817 7680 1 normal | ||
""" | ||
|
||
|
||
class ClusterIdentificationTest(unittest.TestCase): | ||
|
||
def test_detect_cluster(self): | ||
server_name = ["hades", "m", "guil", "helios", "hades"] | ||
clusters = ["hades", "mammouth", "guillimin", "helios"] | ||
|
||
for name, cluster in zip(server_name, clusters): | ||
with patch('smartdispatch.utils.Popen') as mock_communicate: | ||
mock_communicate.return_value.communicate.return_value = (command_output.format(name),) | ||
self.assertEquals(utils.detect_cluster(), cluster) | ||
|
||
# def test_detect_mila_cluster(self): | ||
# with patch('smartdispatch.utils.Popen') as mock_communicate: | ||
# mock_communicate.return_value.communicate.side_effect = OSError | ||
# self.assertIsNone(utils.detect_cluster()) | ||
|
||
def test_get_slurm_cluster_name(self): | ||
clusters = ["graham", "cedar", "mila"] | ||
|
||
for cluster in clusters: | ||
with patch('smartdispatch.utils.Popen') as mock_communicate: | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
bouthilx
Collaborator
|
||
mock_communicate.return_value.communicate.return_value = (slurm_command.format(cluster),) | ||
self.assertEquals(utils.get_slurm_cluster_name(), cluster) |
It would be better to have those 2 before self.pbs. If those fail, we don't care about the first two (pbs), and if the first two fail (pbs), we want to know if it is because the last two (dummy_pbs).