Mercurial > p > roundup > code
changeset 8260:617d85ce4ac3
chore(ruff): variable renames, formatting, sort imports, use with open
| author | John Rouillard <rouilj@ieee.org> |
|---|---|
| date | Sat, 04 Jan 2025 22:34:47 -0500 |
| parents | d7cc63d7a857 |
| children | 28c5030757d3 |
| files | roundup/test/memorydb.py roundup/test/mocknull.py |
| diffstat | 2 files changed, 42 insertions(+), 43 deletions(-) [+] |
line wrap: on
line diff
--- a/roundup/test/memorydb.py Sat Jan 04 20:50:59 2025 -0500 +++ b/roundup/test/memorydb.py Sat Jan 04 22:34:47 2025 -0500 @@ -1,22 +1,14 @@ '''Implement an in-memory hyperdb for testing purposes. ''' +import os import shutil -import os import time -from roundup import date -from roundup import hyperdb -from roundup import roundupdb -from roundup import security -from roundup import password -from roundup import configuration -from roundup.backends import back_anydbm -from roundup.backends import indexer_dbm -from roundup.backends import sessions_dbm -from roundup.backends import indexer_common +from roundup import configuration, date, hyperdb, password, roundupdb, security +from roundup.anypy.strings import s2b +from roundup.backends import back_anydbm, indexer_common, indexer_dbm, sessions_dbm from roundup.support import ensureParentsExist -from roundup.anypy.strings import s2b from roundup.test.tx_Source_detector import init as tx_Source_init default_prefix = '../../share/roundup/templates/classic' @@ -51,31 +43,30 @@ prefix = os.path.join(os.path.dirname(__file__), prefix) schema = os.path.join(prefix, 'schema.py') - vars = hyperdb.__dict__ - vars['Class'] = Class - vars['FileClass'] = FileClass - vars['IssueClass'] = IssueClass - vars['db'] = db - fd = open(schema) - exec(compile(fd.read(), schema, 'exec'), vars) - fd.close() + hyperdb_vars = hyperdb.__dict__ + hyperdb_vars['Class'] = Class + hyperdb_vars['FileClass'] = FileClass + hyperdb_vars['IssueClass'] = IssueClass + hyperdb_vars['db'] = db + + with open(schema) as fd: + exec(compile(fd.read(), schema, 'exec'), hyperdb_vars) initial_data = os.path.join(prefix, 'initial_data.py') - vars = dict(db=db, admin_email='admin@test.com', - adminpw=password.Password('sekrit', config=db.config)) - fd = open(initial_data) - exec(compile(fd.read(), initial_data, 'exec'), vars) - fd.close() + admin_vars = {"db": db, "admin_email": "admin@test.com", + "adminpw": password.Password('sekrit', config=db.config)} + with open(initial_data) as fd: + exec(compile(fd.read(), initial_data, 'exec'), admin_vars) # load standard detectors dirname = os.path.join(prefix, 'detectors') for fn in os.listdir(dirname): if not fn.endswith('.py'): continue # noqa: E701 - vars = {} + exec_vars = {} with open(os.path.join(dirname, fn)) as fd: exec(compile(fd.read(), - os.path.join(dirname, fn), 'exec'), vars) - vars['init'](db) + os.path.join(dirname, fn), 'exec'), exec_vars) + exec_vars['init'](db) tx_Source_init(db) @@ -200,7 +191,7 @@ float(newvalues['__timestamp']) except ValueError: if infoid in self: - del(newvalues['__timestamp']) + del (newvalues['__timestamp']) else: newvalues['__timestamp'] = time.time() self[infoid].update(newvalues) @@ -301,8 +292,8 @@ self.journals = self.__class__.memdb.get('journals', {}) def filename(self, classname, nodeid, property=None, create=0): - shutil.copyfile(__file__, __file__+'.dummy') - return __file__+'.dummy' + shutil.copyfile(__file__, __file__ + '.dummy') + return __file__ + '.dummy' def filesize(self, classname, nodeid, property=None, create=0): return len(self.getfile(classname, nodeid, property)) @@ -423,8 +414,8 @@ self.ids[classname] += 1 return str(self.ids[classname]) - def setid(self, classname, id): - self.ids[classname] = int(id) + def setid(self, classname, nodeid): + self.ids[classname] = int(nodeid) # # Journal @@ -477,8 +468,8 @@ kept_journals = [] for entry in db[key]: # unpack the entry - (nodeid, date_stamp, self.journaltag, action, - params) = entry + (_nodeid, date_stamp, self.journaltag, action, + _params) = entry date_stamp = date_stamp.serialise() # if the entry is after the pack date, _or_ the initial # create entry, then it stays @@ -502,15 +493,13 @@ def export_files(self, dirname, nodeid): dest = self.exportFilename(dirname, nodeid) ensureParentsExist(dest) - f = open(dest, 'wb') - f.write(self.db.files[self.classname, nodeid, None]) - f.close() + with open(dest, 'wb') as f: + f.write(self.db.files[self.classname, nodeid, None]) def import_files(self, dirname, nodeid): source = self.exportFilename(dirname, nodeid) - f = open(source, 'rb') - self.db.files[self.classname, nodeid, None] = f.read() - f.close() + with open(source, 'rb') as f: + self.db.files[self.classname, nodeid, None] = f.read() mime_type = None props = self.getprops() if 'type' in props:
--- a/roundup/test/mocknull.py Sat Jan 04 20:50:59 2025 -0500 +++ b/roundup/test/mocknull.py Sat Jan 04 22:34:47 2025 -0500 @@ -5,6 +5,7 @@ self.__dict__[key] = value def __call__(self, *args, **kwargs): return MockNull() + def __getattr__(self, name): # This allows assignments which assume all intermediate steps are Null # objects if they don't exist yet. @@ -16,16 +17,25 @@ return getattr(self, name) def __getitem__(self, key): return self + def __bool__(self): return False # Python 2 compatibility: __nonzero__ = __bool__ + def __contains__(self, key): return False + def __eq__(self, rhs): return False + def __ne__(self, rhs): return False + def __str__(self): return '' - def __repr__(self): return '<MockNull 0x%x>'%id(self) - def gettext(self, str): return str + + def __repr__(self): return '<MockNull 0x%x>' % id(self) + + def gettext(self, string): return string + _ = gettext + def get(self, name, default=None): try: return self.__dict__[name.lower()]
