Пример #1
0
def test_time_conversion(value, expected):
    """
    Test conversion of (relative) times.

    From docs, acceptable time formats include
    "minutes", "minutes:seconds", "hours:minutes:seconds",
    "days-hours", "days-hours:minutes" and "days-hours:minutes:seconds".
    """
    # pylint: disable=protected-access
    scheduler = SlurmScheduler()
    assert scheduler._convert_time(value) == expected
Пример #2
0
def test_time_conversion_errors(caplog):
    """Test conversion of (relative) times for bad inputs."""
    # pylint: disable=protected-access
    scheduler = SlurmScheduler()

    # Disable logging to avoid excessive output during test
    with caplog.at_level(logging.CRITICAL):
        with pytest.raises(ValueError, match='Unrecognized format for time string.'):
            # Empty string not valid
            scheduler._convert_time('')
        with pytest.raises(ValueError, match='Unrecognized format for time string.'):
            # there should be something after the dash
            scheduler._convert_time('1-')
        with pytest.raises(ValueError, match='Unrecognized format for time string.'):
            # there should be something after the dash
            # there cannot be a dash after the colons
            scheduler._convert_time('1:2-3')
Пример #3
0
    def test_time_conversion(self):
        """
        Test conversion of (relative) times.

        From docs, acceptable time formats include
        "minutes", "minutes:seconds", "hours:minutes:seconds",
        "days-hours", "days-hours:minutes" and "days-hours:minutes:seconds".
        """
        # pylint: disable=protected-access
        scheduler = SlurmScheduler()
        self.assertEqual(scheduler._convert_time('2'), 2 * 60)
        self.assertEqual(scheduler._convert_time('02'), 2 * 60)

        self.assertEqual(scheduler._convert_time('02:3'), 2 * 60 + 3)
        self.assertEqual(scheduler._convert_time('02:03'), 2 * 60 + 3)

        self.assertEqual(scheduler._convert_time('1:02:03'), 3600 + 2 * 60 + 3)
        self.assertEqual(scheduler._convert_time('01:02:03'),
                         3600 + 2 * 60 + 3)

        self.assertEqual(scheduler._convert_time('1-3'), 86400 + 3 * 3600)
        self.assertEqual(scheduler._convert_time('01-3'), 86400 + 3 * 3600)
        self.assertEqual(scheduler._convert_time('01-03'), 86400 + 3 * 3600)

        self.assertEqual(scheduler._convert_time('1-3:5'),
                         86400 + 3 * 3600 + 5 * 60)
        self.assertEqual(scheduler._convert_time('01-3:05'),
                         86400 + 3 * 3600 + 5 * 60)
        self.assertEqual(scheduler._convert_time('01-03:05'),
                         86400 + 3 * 3600 + 5 * 60)

        self.assertEqual(scheduler._convert_time('1-3:5:7'),
                         86400 + 3 * 3600 + 5 * 60 + 7)
        self.assertEqual(scheduler._convert_time('01-3:05:7'),
                         86400 + 3 * 3600 + 5 * 60 + 7)
        self.assertEqual(scheduler._convert_time('01-03:05:07'),
                         86400 + 3 * 3600 + 5 * 60 + 7)

        self.assertEqual(scheduler._convert_time('UNLIMITED'), 2**31 - 1)
        self.assertEqual(scheduler._convert_time('NOT_SET'), None)

        # Disable logging to avoid excessive output during test
        logging.disable(logging.ERROR)
        with self.assertRaises(ValueError):
            # Empty string not valid
            scheduler._convert_time('')
        with self.assertRaises(ValueError):
            # there should be something after the dash
            scheduler._convert_time('1-')
        with self.assertRaises(ValueError):
            # there should be something after the dash
            # there cannot be a dash after the colons
            scheduler._convert_time('1:2-3')
        # Reset logging level
        logging.disable(logging.NOTSET)