<s> """<STR_LIT>""" <EOL> import os <EOL> import tempfile <EOL> import unittest <EOL> from ganeti import constants <EOL> from ganeti import uidpool <EOL> from ganeti import errors <EOL> from ganeti import pathutils <EOL> import testutils <EOL> class TestUidPool ( testutils . GanetiTestCase ) : <EOL> """<STR_LIT>""" <EOL> def setUp ( self ) : <EOL> self . old_uid_min = constants . UIDPOOL_UID_MIN <EOL> self . old_uid_max = constants . UIDPOOL_UID_MAX <EOL> constants . UIDPOOL_UID_MIN = <NUM_LIT:1> <EOL> constants . UIDPOOL_UID_MAX = <NUM_LIT:10> <EOL> pathutils . UIDPOOL_LOCKDIR = tempfile . mkdtemp ( ) <EOL> def tearDown ( self ) : <EOL> constants . UIDPOOL_UID_MIN = self . old_uid_min <EOL> constants . UIDPOOL_UID_MAX = self . old_uid_max <EOL> for name in os . listdir ( pathutils . UIDPOOL_LOCKDIR ) : <EOL> os . unlink ( os . path . join ( pathutils . UIDPOOL_LOCKDIR , name ) ) <EOL> os . rmdir ( pathutils . UIDPOOL_LOCKDIR ) <EOL> def testParseUidPool ( self ) : <EOL> self . assertEqualValues ( <EOL> uidpool . ParseUidPool ( "<STR_LIT>" ) , <EOL> [ ( <NUM_LIT:1> , <NUM_LIT:100> ) , ( <NUM_LIT:200> , <NUM_LIT:200> ) ] ) <EOL> self . assertEqualValues ( <EOL> uidpool . ParseUidPool ( "<STR_LIT>" , separator = "<STR_LIT::>" ) , <EOL> [ ( <NUM_LIT:1000> , <NUM_LIT:1000> ) , ( <NUM_LIT> , <NUM_LIT> ) ] ) <EOL> self . assertEqualValues ( <EOL> uidpool . ParseUidPool ( "<STR_LIT>" , separator = "<STR_LIT:\n>" ) , <EOL> [ ( <NUM_LIT:1000> , <NUM_LIT:1000> ) , ( <NUM_LIT> , <NUM_LIT> ) ] ) <EOL> def testCheckUidPool ( self ) : <EOL> self . assertRaises ( errors . OpPrereqError , <EOL> uidpool . CheckUidPool , <EOL> [ ( <NUM_LIT:0> , <NUM_LIT:0> ) ] ) <EOL> self . assertRaises ( errors . OpPrereqError , <EOL> uidpool . CheckUidPool , <EOL> [ ( <NUM_LIT:11> , <NUM_LIT:11> ) ] ) <EOL> self . assertRaises ( errors . OpPrereqError , <EOL> uidpool . CheckUidPool , <EOL> [ ( <NUM_LIT:2> , <NUM_LIT:1> ) ] ) <EOL> def testFormatUidPool ( self ) : <EOL> self . assertEqualValues ( <EOL> uidpool . FormatUidPool ( [ ( <NUM_LIT:1> , <NUM_LIT:100> ) , ( <NUM_LIT:200> , <NUM_LIT:200> ) ] ) , <EOL> "<STR_LIT>" ) <EOL> self . assertEqualValues ( <EOL> uidpool . FormatUidPool ( [ ( <NUM_LIT:1> , <NUM_LIT:100> ) , ( <NUM_LIT:200> , <NUM_LIT:200> ) ] , separator = "<STR_LIT::>" ) , <EOL> "<STR_LIT>" ) <EOL> self . assertEqualValues ( <EOL> uidpool . FormatUidPool ( [ ( <NUM_LIT:1> , <NUM_LIT:100> ) , ( <NUM_LIT:200> , <NUM_LIT:200> ) ] , separator = "<STR_LIT:\n>" ) , <EOL> "<STR_LIT>" ) <EOL> def testRequestUnusedUid ( self ) : <EOL> for uid in <NUM_LIT:0> , os . getuid ( ) : <EOL> self . assertRaises ( errors . LockError , <EOL> uidpool . RequestUnusedUid , <EOL> set ( [ uid ] ) ) <EOL> uid = uidpool . RequestUnusedUid ( set ( [ - <NUM_LIT:1> ] ) ) <EOL> self . assertEqualValues ( uid . GetUid ( ) , - <NUM_LIT:1> ) <EOL> self . assertRaises ( errors . LockError , <EOL> uidpool . RequestUnusedUid , <EOL> set ( [ - <NUM_LIT:1> ] ) ) <EOL> uid . Unlock ( ) <EOL> uid = uidpool . RequestUnusedUid ( set ( [ - <NUM_LIT:1> ] ) ) <EOL> self . assertEqualValues ( uid . GetUid ( ) , - <NUM_LIT:1> ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> testutils . GanetiTestProgram ( ) </s>
