Skip to content

Commit d8c2a22

Browse files
committed
Merge remote-tracking branch 'origin/master' into edge
2 parents 715cb57 + 3f1efcb commit d8c2a22

File tree

2 files changed

+52
-16
lines changed

2 files changed

+52
-16
lines changed

mig/server/indexdoi.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# --- BEGIN_HEADER ---
55
#
66
# indexdoi - Build index of imported site DOIs
7-
# Copyright (C) 2003-2022 The MiG Project lead by Brian Vinter
7+
# Copyright (C) 2003-2024 The MiG Project lead by Brian Vinter
88
#
99
# This file is part of MiG.
1010
#
@@ -83,7 +83,7 @@ def extract_imported_doi_dicts(configurationi):
8383
# Ignore msec in stamp
8484
now -= datetime.timedelta(microseconds=now.microsecond)
8585

86-
doi_exports = []
86+
doi_exports, doi_count = [], 0
8787
doi_imports = extract_imported_doi_dicts(configuration)
8888
if verbose:
8989
print("extracted %d doi entries: %s" % len(doi_imports))
@@ -115,10 +115,12 @@ def extract_imported_doi_dicts(configurationi):
115115
if verbose:
116116
print("Found existing DOI data in %s" % doi_path)
117117
doi_exports.append((plain_doi, archive_url))
118+
doi_count += 1
118119

119120
if dump:
120121
fill_helpers = {'short_title': configuration.short_title,
121122
'update_stamp': now,
123+
'doi_count': doi_count,
122124
}
123125
publish_title = '%(short_title)s DOI Index' % fill_helpers
124126

@@ -143,8 +145,8 @@ def extract_imported_doi_dicts(configurationi):
143145
<div id="doi-index" class="staticpage">
144146
<h2 class="staticpage">%(short_title)s DOI Index</h2>
145147
<div class="doi-index-intro">
146-
A list of all known DOIs pointing to Archives at %(short_title)s, sorted with
147-
the most recently discovered ones at the top.
148+
A list of all %(doi_count)d known DOIs pointing to Archives at %(short_title)s, sorted
149+
with the most recently discovered ones at the top.
148150
</div>
149151
<div class="vertical-spacer"></div>
150152
<div class="info leftpad">
@@ -173,15 +175,15 @@ def extract_imported_doi_dicts(configurationi):
173175
index_fd.write(contents % fill_helpers)
174176
index_fd.close()
175177
msg = "Published index of %d DOIs in %s" % \
176-
(len(doi_exports), doi_index_path)
178+
(doi_count, doi_index_path)
177179
_logger.info(msg)
178180
if verbose:
179181
print(msg)
180182
except Exception as exc:
181183
msg = "failed to write %s: %s" % (doi_index_path, exc)
182184
_logger.error(msg)
183185
print("Error writing index of %d DOIs in %s" %
184-
(len(doi_exports), doi_index_path))
186+
(doi_count, doi_index_path))
185187
sys.exit(1)
186188

187189
sys.exit(0)

tests/support.py

Lines changed: 44 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,32 @@
1+
#!/usr/bin/python
2+
# -*- coding: utf-8 -*-
3+
#
4+
# --- BEGIN_HEADER ---
5+
#
6+
# support - helper functions for unit testing
7+
# Copyright (C) 2003-2024 The MiG Project by the Science HPC Center at UCPH
8+
#
9+
# This file is part of MiG.
10+
#
11+
# MiG is free software: you can redistribute it and/or modify
12+
# it under the terms of the GNU General Public License as published by
13+
# the Free Software Foundation; either version 2 of the License, or
14+
# (at your option) any later version.
15+
#
16+
# MiG is distributed in the hope that it will be useful,
17+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
18+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19+
# GNU General Public License for more details.
20+
#
21+
# You should have received a copy of the GNU General Public License
22+
# along with this program; if not, write to the Free Software
23+
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
24+
#
25+
# -- END_HEADER ---
26+
#
27+
28+
"""Supporting functions for the unit test framework"""
29+
130
from collections import defaultdict
231
import errno
332
import logging
@@ -23,16 +52,16 @@
2352
# provision an output directory up-front
2453
try:
2554
os.mkdir(TEST_OUTPUT_DIR)
26-
except EnvironmentError as e:
27-
if e.errno == errno.EEXIST:
55+
except EnvironmentError as enverr:
56+
if enverr.errno == errno.EEXIST:
2857
pass # FileExistsError
2958

30-
# basic global logging configuration for testing
31-
#
32-
# arrange a stream that ignores all logging messages
59+
# Basic global logging configuration for testing
3360

3461

3562
class BlackHole:
63+
"""Arrange a stream that ignores all logging messages"""
64+
3665
def write(self, message):
3766
pass
3867

@@ -91,7 +120,7 @@ def warning(self, line):
91120
self._append_as('warning', line)
92121

93122
def write(self, message):
94-
channel, namespace, specifics = message.split(':', maxsplit=2)
123+
channel, namespace, specifics = message.split(':', 2)
95124

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

104133
@staticmethod
105134
def identify_unclosed_file(specifics):
106-
filename, lineno, exc_name, message = specifics.split(':', maxsplit=3)
135+
filename, lineno, exc_name, message = specifics.split(':', 3)
136+
107137
exc_name = exc_name.lstrip()
108138
if exc_name != 'ResourceWarning':
109139
return
140+
110141
matched = FakeLogger.RE_UNCLOSEDFILE.match(message.lstrip())
111142
if matched is None:
112143
return
144+
113145
relative_testfile = os.path.relpath(filename, start=MIG_BASE)
114146
relative_outputfile = os.path.relpath(
115147
matched.groups('location')[0], start=TEST_BASE)
@@ -162,7 +194,8 @@ def logger(self):
162194
return self._logger
163195

164196
def assertPathExists(self, relative_path):
165-
assert(not os.path.isabs(relative_path)), "expected relative path within output folder"
197+
assert not os.path.isabs(
198+
relative_path), "expected relative path within output folder"
166199
absolute_path = os.path.join(TEST_OUTPUT_DIR, relative_path)
167200
stat_result = os.stat(absolute_path)
168201
if stat.S_ISDIR(stat_result.st_mode):
@@ -172,12 +205,13 @@ def assertPathExists(self, relative_path):
172205

173206

174207
def cleanpath(relative_path, test_case):
175-
assert(isinstance(test_case, MigTestCase))
208+
assert isinstance(test_case, MigTestCase)
176209
tmp_path = os.path.join(TEST_OUTPUT_DIR, relative_path)
177210
test_case._cleanup_paths.add(tmp_path)
178211

212+
179213
def temppath(relative_path, test_case, skip_clean=False):
180-
assert(isinstance(test_case, MigTestCase))
214+
assert isinstance(test_case, MigTestCase)
181215
tmp_path = os.path.join(TEST_OUTPUT_DIR, relative_path)
182216
if not skip_clean:
183217
test_case._cleanup_paths.add(tmp_path)

0 commit comments

Comments
 (0)