Skip to content

Commit

Permalink
Add a test testing that there is no VERSION < max(RELEASE_NOTE_VERSION).
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 687272185
  • Loading branch information
marcenacp authored and The TensorFlow Datasets Authors committed Oct 18, 2024
1 parent 645e29f commit d16f41d
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 6 deletions.
4 changes: 3 additions & 1 deletion tensorflow_datasets/core/registered_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,9 @@ class SkipDataset(registered.RegisteredDataset, skip_registration=True):
def test_custom_name():
"""Tests that builder can have custom names."""

class SomeCustomNameBuilder(registered.RegisteredDataset):
class SomeCustomNameBuilder(
registered.RegisteredDataset, skip_registration=True
):
name = "custom_name"

assert "custom_name" == SomeCustomNameBuilder.name
Expand Down
2 changes: 1 addition & 1 deletion tensorflow_datasets/datasets/asqa/asqa_dataset_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def _features():
class Builder(tfds.core.GeneratorBasedBuilder):
"""DatasetBuilder for asqa dataset."""

VERSION = tfds.core.Version('1.0.0')
VERSION = tfds.core.Version('2.0.0')
RELEASE_NOTES = {
'2.0.0': 'Sample ID goes from int32 (overflowing) to int64.',
'1.0.0': 'Initial release.',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
class Builder(tfds.core.GeneratorBasedBuilder):
"""DAS beamformed phantom images and paired post-processed images."""

VERSION = tfds.core.Version('1.0.1')
VERSION = tfds.core.Version('2.0.0')
RELEASE_NOTES = {
'2.0.0': r'Fix timestamp_id from %Y%m%d%H%M%S to posix timestamp.',
'1.0.1': 'Fixes parsing of boolean field `harmonic`.',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def _create_builder_configs():
class Builder(tfds.core.GeneratorBasedBuilder):
"""An ImageNet test set recollected by following the original protocol."""

VERSION = tfds.core.Version('3.0.0')
VERSION = tfds.core.Version('3.1.0')
SUPPORTED_VERSIONS = [
tfds.core.Version('2.0.0'),
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
class Builder(tfds.core.GeneratorBasedBuilder):
"""Street View House Numbers (SVHN) Dataset, cropped version."""

VERSION = tfds.core.Version("3.0.0")
VERSION = tfds.core.Version("3.1.0")
SUPPORTED_VERSIONS = [
tfds.core.Version("3.1.0"),
]
Expand Down
67 changes: 67 additions & 0 deletions tensorflow_datasets/testing/version_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# coding=utf-8
# Copyright 2024 The TensorFlow Datasets Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import dataclasses
import inspect

import tensorflow_datasets as tfds


@dataclasses.dataclass(frozen=True, kw_only=True)
class _BuilderWithVersionMismatch:
name: str
file: str
version: str
max_version_in_release_notes: str


def test_internal_datasets_have_versions_on_line_with_the_release_notes():
builders = tfds.list_builders(with_community_datasets=False)
assert builders
builders_with_version_mismatch: list[_BuilderWithVersionMismatch] = []
for builder in builders:
builder_cls = tfds.core.registered.imported_builder_cls(builder)
if builder_cls.VERSION and builder_cls.RELEASE_NOTES:
max_version_in_release_notes = max(
[tfds.core.Version(version) for version in builder_cls.RELEASE_NOTES]
)
version = tfds.core.Version(builder_cls.VERSION)
if version < max_version_in_release_notes:
# This means the builder is as follow:
# ```
# RELEASE_NOTES = {
# '1.0.1': 'Bug fix.',
# '1.0.0': 'Initial release.',
# }
# VERSION = '1.0.0' # <- Someone forgot to increment this version.
# ```
file = inspect.getfile(builder_cls).split('tensorflow_datasets/')[-1]
builders_with_version_mismatch.append(
_BuilderWithVersionMismatch(
name=builder_cls.name,
file=file,
version=version,
max_version_in_release_notes=max_version_in_release_notes,
)
)
if builders_with_version_mismatch:
error = 'The following datasets have a version mismatch:'
for builder_cls in builders_with_version_mismatch:
error += (
f'\n - Dataset {builder_cls.name} ({builder_cls.file}) has VERSION='
f'"{builder_cls.version}" but RELEASE_NOTES contains version'
f' "{builder_cls.max_version_in_release_notes}".'
)
raise ValueError(error)
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class DolphinNumberWord(tfds.core.GeneratorBasedBuilder):

__count__ = 0

VERSION = tfds.core.Version('0.0.2')
VERSION = tfds.core.Version('0.0.3')
RELEASE_NOTES = {
'0.0.1': 'Initial release.',
'0.0.2': (
Expand Down

0 comments on commit d16f41d

Please sign in to comment.