VirtualBox

Changeset 94127 in vbox


Ignore:
Timestamp:
Mar 8, 2022 2:44:28 PM (3 years ago)
Author:
vboxsync
Message:

ValKit/tests: pylint 2.9.6 adjustments (mostly about using 'with' statements).

Location:
trunk/src/VBox/ValidationKit/tests
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/ValidationKit/tests/additions/tdAddBasic1.py

    r93734 r94127  
    142142                          % (uuid.uuid4(), self.sVBoxValidationKitIso, sGaIso);
    143143            reporter.log2('Using VISO combining ValKit and GAs "%s": %s' % (sVisoContent, sGaViso));
    144             oGaViso = open(sGaViso, 'w');
    145             oGaViso.write(sVisoContent);
    146             oGaViso.close();
     144            with open(sGaViso, 'w') as oGaViso:
     145                oGaViso.write(sVisoContent);
    147146            sGaIso = sGaViso;
    148147
  • trunk/src/VBox/ValidationKit/tests/additions/tdAddGuestCtrl.py

    r93889 r94127  
    151151        sHstFileName = os.path.join(oTstDrv.sScratchPath, sFileName);
    152152        try:
    153             oCurTestFile = open(sHstFileName, "wb");
    154             oCurTestFile.write(aData);
    155             oCurTestFile.close();
     153            with open(sHstFileName, "wb") as oCurTestFile:
     154                oCurTestFile.write(aData);
    156155        except:
    157156            return reporter.error('Unable to create temporary file for "%s"' % (sDesc,));
     
    17721771                sDst = os.path.join(sDst, oTest.oSrc.sName);
    17731772            try:
    1774                 oFile = open(sDst, 'rb');
     1773                oFile = open(sDst, 'rb');                       # pylint: disable=consider-using-with
    17751774            except:
    17761775                return reporter.errorXcpt('open(%s) failed during verfication' % (sDst,));
     
    18111810                    sFilePath = os.path.join(sHostPath, oFsObj.sName);
    18121811                    try:
    1813                         oFile = open(sFilePath, 'rb');
     1812                        oFile = open(sFilePath, 'rb');          # pylint: disable=consider-using-with
    18141813                    except:
    18151814                        fRc = reporter.errorXcpt('open(%s) failed during verfication' % (sFilePath,));
     
    40304029            return (False, oTxsSession);
    40314030
    4032         for sPath in self.oTestFiles.dPaths:
    4033             oFsObj = self.oTestFiles.dPaths[sPath];
     4031        for oFsObj in self.oTestFiles.dPaths.values():
    40344032            reporter.log2('testGuestCtrlFileStat: %s sPath=%s'
    40354033                          % ('file' if isinstance(oFsObj, testfileset.TestFile) else 'dir ', limitString(oFsObj.sPath),));
     
    46964694    def __generateFile(sName, cbFile):
    46974695        """ Helper for generating a file with a given size. """
    4698         oFile = open(sName, 'wb');
    4699         while cbFile > 0:
    4700             cb = cbFile if cbFile < 256*1024 else 256*1024;
    4701             oFile.write(bytearray(random.getrandbits(8) for _ in xrange(cb)));
    4702             cbFile -= cb;
    4703         oFile.close();
     4696        with open(sName, 'wb') as oFile:
     4697            while cbFile > 0:
     4698                cb = cbFile if cbFile < 256*1024 else 256*1024;
     4699                oFile.write(bytearray(random.getrandbits(8) for _ in xrange(cb)));
     4700                cbFile -= cb;
     4701        return True;
    47044702
    47054703    def testGuestCtrlCopyTo(self, oSession, oTxsSession, oTestVm): # pylint: disable=too-many-locals
     
    47704768        sEmptyFileHst = os.path.join(self.oTstDrv.sScratchPath, 'gctrl-empty.data');
    47714769        try:
    4772             oFile = open(sEmptyFileHst, "wb");
    4773             oFile.close();
     4770            open(sEmptyFileHst, "wb").close();                  # pylint: disable=consider-using-with
    47744771        except:
    47754772            return reporter.errorXcpt('sEmptyFileHst=%s' % (sEmptyFileHst,));
  • trunk/src/VBox/ValidationKit/tests/api/tdAppliance1.py

    r93115 r94127  
    161161        try:
    162162            os.mkdir(sTmpDir, 0o755);
    163             oTarFile = tarfile.open(sOva, 'r:*');
     163            oTarFile = tarfile.open(sOva, 'r:*'); # No 'with' support in 2.6.   pylint: disable=consider-using-with
    164164            oTarFile.extractall(sTmpDir);
    165165            oTarFile.close();
  • trunk/src/VBox/ValidationKit/tests/api/tdMoveVm1.py

    r93115 r94127  
    397397        fRc = self.oTstDrv.terminateVmBySession(oSession)
    398398
    399         if fRc is True or False:
     399        if fRc is True:
    400400            # Create a new Session object for moving VM.
    401401            oSession = self.oTstDrv.openSession(oMachine)
  • trunk/src/VBox/ValidationKit/tests/serial/loopback.py

    r93115 r94127  
    224224        Shutdown any connection and wait for it to become idle.
    225225        """
    226         self.oLock.acquire();
    227         self.fShutdown = True;
    228         self.oLock.release();
     226        with self.oLock:
     227            self.fShutdown = True;
    229228        self.oIoPumper.shutdown();
    230229
     
    233232        Returns whether the I/O pumping thread should shut down.
    234233        """
    235         self.oLock.acquire();
    236         fShutdown = self.fShutdown;
    237         self.oLock.release();
     234        with self.oLock:
     235            fShutdown = self.fShutdown;
    238236
    239237        return fShutdown;
  • trunk/src/VBox/ValidationKit/tests/serial/tdSerial1.py

    r93115 r94127  
    230230            cLast = 0;
    231231            try:
    232                 oFile = open(self.sLocation, 'rb');
    233                 sFmt = '=I';
    234                 cBytes = 4;
    235                 for i in xrange(1048576 // 4):
    236                     _ = i;
    237                     sData = oFile.read(cBytes);
    238                     tupUnpacked = struct.unpack(sFmt, sData);
    239                     cLast = cLast + 1;
    240                     if tupUnpacked[0] != cLast:
    241                         reporter.testFailure('Corruption detected, expected counter value %s, got %s'
    242                                              % (cLast + 1, tupUnpacked[0]));
    243                         break;
    244                 oFile.close();
     232                with open(self.sLocation, 'rb') as oFile:
     233                    sFmt = '=I';
     234                    cBytes = 4;
     235                    for i in xrange(1048576 // 4):
     236                        _ = i;
     237                        sData = oFile.read(cBytes);
     238                        tupUnpacked = struct.unpack(sFmt, sData);
     239                        cLast = cLast + 1;
     240                        if tupUnpacked[0] != cLast:
     241                            reporter.testFailure('Corruption detected, expected counter value %s, got %s'
     242                                                 % (cLast + 1, tupUnpacked[0],));
     243                            break;
    245244            except:
    246245                reporter.logXcpt();
  • trunk/src/VBox/ValidationKit/tests/storage/remoteexecutor.py

    r93115 r94127  
    243243            sFileId = self.sScratchPath + '/' + sFilename;
    244244            try:
    245                 oFile = open(sFileId, 'wb');
    246                 oFile.write(sContent);
    247                 oFile.close();
     245                with open(sFileId, 'wb') as oFile:
     246                    oFile.write(sContent);
    248247            except:
    249248                sFileId = None;
  • trunk/src/VBox/ValidationKit/tests/unittests/tdUnitTest1.py

    r93904 r94127  
    10511051        # Open /dev/null for use as stdin further down.
    10521052        try:
    1053             oDevNull = open(os.path.devnull, 'w+');
     1053            oDevNull = open(os.path.devnull, 'w+');             # pylint: disable=consider-using-with
    10541054        except:
    10551055            oDevNull = None;
  • trunk/src/VBox/ValidationKit/tests/usb/tst-utsgadget.py

    r93115 r94127  
    3636sys.path.insert(0, '..');
    3737sys.path.insert(0, '../..');
     38from common import utils;
     39from testdriver import reporter;
    3840import usbgadget;
    39 import testdriver.reporter as reporter
    40 from common import utils;
    4141
    4242
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette