Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into edge
Browse files Browse the repository at this point in the history
  • Loading branch information
jonasbardino committed May 29, 2024
2 parents 715cb57 + 3f1efcb commit d8c2a22
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 16 deletions.
14 changes: 8 additions & 6 deletions mig/server/indexdoi.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# --- BEGIN_HEADER ---
#
# indexdoi - Build index of imported site DOIs
# Copyright (C) 2003-2022 The MiG Project lead by Brian Vinter
# Copyright (C) 2003-2024 The MiG Project lead by Brian Vinter
#
# This file is part of MiG.
#
Expand Down Expand Up @@ -83,7 +83,7 @@ def extract_imported_doi_dicts(configurationi):
# Ignore msec in stamp
now -= datetime.timedelta(microseconds=now.microsecond)

doi_exports = []
doi_exports, doi_count = [], 0
doi_imports = extract_imported_doi_dicts(configuration)
if verbose:
print("extracted %d doi entries: %s" % len(doi_imports))
Expand Down Expand Up @@ -115,10 +115,12 @@ def extract_imported_doi_dicts(configurationi):
if verbose:
print("Found existing DOI data in %s" % doi_path)
doi_exports.append((plain_doi, archive_url))
doi_count += 1

if dump:
fill_helpers = {'short_title': configuration.short_title,
'update_stamp': now,
'doi_count': doi_count,
}
publish_title = '%(short_title)s DOI Index' % fill_helpers

Expand All @@ -143,8 +145,8 @@ def extract_imported_doi_dicts(configurationi):
<div id="doi-index" class="staticpage">
<h2 class="staticpage">%(short_title)s DOI Index</h2>
<div class="doi-index-intro">
A list of all known DOIs pointing to Archives at %(short_title)s, sorted with
the most recently discovered ones at the top.
A list of all %(doi_count)d known DOIs pointing to Archives at %(short_title)s, sorted
with the most recently discovered ones at the top.
</div>
<div class="vertical-spacer"></div>
<div class="info leftpad">
Expand Down Expand Up @@ -173,15 +175,15 @@ def extract_imported_doi_dicts(configurationi):
index_fd.write(contents % fill_helpers)
index_fd.close()
msg = "Published index of %d DOIs in %s" % \
(len(doi_exports), doi_index_path)
(doi_count, doi_index_path)
_logger.info(msg)
if verbose:
print(msg)
except Exception as exc:
msg = "failed to write %s: %s" % (doi_index_path, exc)
_logger.error(msg)
print("Error writing index of %d DOIs in %s" %
(len(doi_exports), doi_index_path))
(doi_count, doi_index_path))
sys.exit(1)

sys.exit(0)
54 changes: 44 additions & 10 deletions tests/support.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,32 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
#
# --- BEGIN_HEADER ---
#
# support - helper functions for unit testing
# Copyright (C) 2003-2024 The MiG Project by the Science HPC Center at UCPH
#
# This file is part of MiG.
#
# MiG is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# MiG is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# -- END_HEADER ---
#

"""Supporting functions for the unit test framework"""

from collections import defaultdict
import errno
import logging
Expand All @@ -23,16 +52,16 @@
# provision an output directory up-front
try:
os.mkdir(TEST_OUTPUT_DIR)
except EnvironmentError as e:
if e.errno == errno.EEXIST:
except EnvironmentError as enverr:
if enverr.errno == errno.EEXIST:
pass # FileExistsError

# basic global logging configuration for testing
#
# arrange a stream that ignores all logging messages
# Basic global logging configuration for testing


class BlackHole:
"""Arrange a stream that ignores all logging messages"""

def write(self, message):
pass

Expand Down Expand Up @@ -91,7 +120,7 @@ def warning(self, line):
self._append_as('warning', line)

def write(self, message):
channel, namespace, specifics = message.split(':', maxsplit=2)
channel, namespace, specifics = message.split(':', 2)

# ignore everything except warnings sent by th python runtime
if not (channel == 'WARNING' and namespace == 'py.warnings'):
Expand All @@ -103,13 +132,16 @@ def write(self, message):

@staticmethod
def identify_unclosed_file(specifics):
filename, lineno, exc_name, message = specifics.split(':', maxsplit=3)
filename, lineno, exc_name, message = specifics.split(':', 3)

exc_name = exc_name.lstrip()
if exc_name != 'ResourceWarning':
return

matched = FakeLogger.RE_UNCLOSEDFILE.match(message.lstrip())
if matched is None:
return

relative_testfile = os.path.relpath(filename, start=MIG_BASE)
relative_outputfile = os.path.relpath(
matched.groups('location')[0], start=TEST_BASE)
Expand Down Expand Up @@ -162,7 +194,8 @@ def logger(self):
return self._logger

def assertPathExists(self, relative_path):
assert(not os.path.isabs(relative_path)), "expected relative path within output folder"
assert not os.path.isabs(
relative_path), "expected relative path within output folder"
absolute_path = os.path.join(TEST_OUTPUT_DIR, relative_path)
stat_result = os.stat(absolute_path)
if stat.S_ISDIR(stat_result.st_mode):
Expand All @@ -172,12 +205,13 @@ def assertPathExists(self, relative_path):


def cleanpath(relative_path, test_case):
assert(isinstance(test_case, MigTestCase))
assert isinstance(test_case, MigTestCase)
tmp_path = os.path.join(TEST_OUTPUT_DIR, relative_path)
test_case._cleanup_paths.add(tmp_path)


def temppath(relative_path, test_case, skip_clean=False):
assert(isinstance(test_case, MigTestCase))
assert isinstance(test_case, MigTestCase)
tmp_path = os.path.join(TEST_OUTPUT_DIR, relative_path)
if not skip_clean:
test_case._cleanup_paths.add(tmp_path)
Expand Down

0 comments on commit d8c2a22

Please sign in to comment.