Skip to content

Commit

Permalink
Remove dependencies of copyright year from test/data files.
Browse files Browse the repository at this point in the history
  • Loading branch information
RubelMozumder committed Jan 15, 2025
1 parent 8cdf4b2 commit 302ed12
Show file tree
Hide file tree
Showing 18 changed files with 58 additions and 40 deletions.
1 change: 0 additions & 1 deletion src/nyaml/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ def generate_nxdl_or_retrieve_nxdl(yaml_file, out_xml_file, verbose):
pa_path, rel_file = file_path.parent, file_path.name
sep_yaml = (pa_path / f"temp_{rel_file}").as_posix()
hash_found = separate_hash_yaml_and_nxdl(yaml_file, sep_yaml, out_xml_file)

if hash_found:
gen_hash = get_sha256_hash(sep_yaml)
if hash_found == gen_hash:
Expand Down
2 changes: 0 additions & 2 deletions src/nyaml/nyaml2nxdl.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@

def get_nxdl_copyright_license(nxdl_file):
"""Extract the license part from nxdl file if nxdl file as input."""
copyright_lincense = ""
comment_start_sym = "^<!--"
comment_end_sym = "-->\n+$"
is_comment_start = False
Expand All @@ -79,7 +78,6 @@ def get_nxdl_copyright_license(nxdl_file):
comment += line
# Varifiy for copyright comment
if is_comment_start and is_comment_end:
print(" ##### comment : ", comment)
if is_copyright_comment(comment):
return comment
else:
Expand Down
30 changes: 15 additions & 15 deletions tests/data/NXentry.nxdl.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
<?xml-stylesheet type="text/xsl" href="nxdlformat.xsl"?>
<!--
# NeXus - Neutron and X-ray Common Data Format
#
# Copyright (C) 2014-2022 NeXus International Advisory Committee (NIAC)
#
#
# Copyright (C) 2010-2020 NeXus International Advisory Committee (NIAC)
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
Expand All @@ -24,7 +24,7 @@
<definition xmlns="http://definition.nexusformat.org/nxdl/3.1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" category="base" type="group" name="NXentry" extends="NXobject" xsi:schemaLocation="http://definition.nexusformat.org/nxdl/3.1 ../nxdl.xsd">
<doc>
(**required**) :ref:`NXentry` describes the measurement.

The top-level NeXus group which contains all the data and associated
information that comprise a single measurement.
It is mandatory that there is at least one
Expand All @@ -35,15 +35,15 @@
.. index:: find the default plottable data
.. index:: plotting
.. index:: default attribute value

Declares which :ref:`NXdata` group contains the data
to be shown by default.
It is used to resolve ambiguity when
one :ref:`NXdata` group exists.
The value :ref:`names &lt;validItemName&gt;` a child group. If that group
itself has a ``default`` attribute, continue this chain until an
:ref:`NXdata` group is reached.

For more information about how NeXus identifies the default
plottable data, see the
:ref:`Find Plottable Data, v3 &lt;Find-Plottable-Data-v3&gt;`
Expand All @@ -53,7 +53,7 @@
<group type="NXdata">
<doc>
The data group

.. note:: Before the NIAC2016 meeting [#]_, at least one
:ref:`NXdata` group was required in each :ref:`NXentry` group.
At the NIAC2016 meeting, it was decided to make :ref:`NXdata`
Expand All @@ -64,17 +64,17 @@
It is permissable to omit the NXdata group only when
defining the default plot is not practical or possible
from the available data.

For example, neutron event data may not have anything that
makes a useful plot without extensive processing.

Certain application definitions override this decision and
require an :ref:`NXdata` group
in the :ref:`NXentry` group. The ``minOccurs=0`` attribute
in the application definition will indicate the
:ref:`NXdata` group
is optional, otherwise, it is required.

.. [#] NIAC2016:
https://www.nexusformat.org/NIAC2016.html,
https://github.com/nexusformat/NIAC/issues/16
Expand Down Expand Up @@ -136,25 +136,25 @@
<field name="features">
<doc>
Reserved for future use by NIAC.

See https://github.com/nexusformat/definitions/issues/382
</doc>
</field>
<field name="definition">
<doc>
(alternate use: see same field in :ref:`NXsubentry` for preferred)

Official NeXus NXDL schema to which this entry conforms which must be
the name of the NXDL file (case sensitive without the file extension)
that the NXDL schema is defined in.

For example the ``definition`` field for a file that conformed to the
*NXarpes.nxdl.xml* definition must contain the string **NXarpes**.

This field is provided so that :ref:`NXentry` can be the overlay position
in a NeXus data file for an application definition and its
set of groups, fields, and attributes.

*It is advised* to use :ref:`NXsubentry`, instead, as the overlay position.
</doc>
<attribute name="version">
Expand Down
6 changes: 3 additions & 3 deletions tests/data/Ref_NXattributes.nxdl.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
<?xml-stylesheet type="text/xsl" href="nxdlformat.xsl"?>
<!--
# NeXus - Neutron and X-ray Common Data Format
#
# Copyright (C) 2014-2022 NeXus International Advisory Committee (NIAC)
#
#
# Copyright (C) 2010-2020 NeXus International Advisory Committee (NIAC)
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
Expand Down
6 changes: 3 additions & 3 deletions tests/data/Ref_NXcomment_yaml2nxdl.nxdl.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
<?xml-stylesheet type="text/xsl" href="nxdlformat.xsl"?>
<!--
# NeXus - Neutron and X-ray Common Data Format
#
# Copyright (C) 2014-2022 NeXus International Advisory Committee (NIAC)
#
#
# Copyright (C) 2010-2020 NeXus International Advisory Committee (NIAC)
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
Expand Down
2 changes: 1 addition & 1 deletion tests/data/Ref_NXellips.nxdl.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<!--
# NeXus - Neutron and X-ray Common Data Format
#
# Copyright (C) 2025-2029 NeXus International Advisory Committee (NIAC)
# Copyright (C) 2010-2010 NeXus International Advisory Committee (NIAC)
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
Expand Down
2 changes: 1 addition & 1 deletion tests/data/Ref_NXellipsometry-docCheck.nxdl.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<!--
# NeXus - Neutron and X-ray Common Data Format
#
# Copyright (C) 2014-2022 NeXus International Advisory Committee (NIAC)
# Copyright (C) 2010-2020 NeXus International Advisory Committee (NIAC)
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
Expand Down
2 changes: 1 addition & 1 deletion tests/data/Ref_NXentry.nxdl.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<!--
# NeXus - Neutron and X-ray Common Data Format
#
# Copyright (C) 2025-2029 NeXus International Advisory Committee (NIAC)
# Copyright (C) 2010-2020 NeXus International Advisory Committee (NIAC)
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
Expand Down
2 changes: 1 addition & 1 deletion tests/data/Ref_NXentry.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ NXentry(NXobject):
# <!--
# # NeXus - Neutron and X-ray Common Data Format
# #
# # Copyright (C) 2025-2029 NeXus International Advisory Committee (NIAC)
# # Copyright (C) 2010-2020 NeXus International Advisory Committee (NIAC)
# #
# # This library is free software; you can redistribute it and/or
# # modify it under the terms of the GNU Lesser General Public
Expand Down
6 changes: 3 additions & 3 deletions tests/data/Ref_NXmytests.nxdl.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
<?xml-stylesheet type="text/xsl" href="nxdlformat.xsl"?>
<!--
# NeXus - Neutron and X-ray Common Data Format
#
# Copyright (C) 2014-2022 NeXus International Advisory Committee (NIAC)
#
#
# Copyright (C) 2010-2020 NeXus International Advisory Committee (NIAC)
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
Expand Down
2 changes: 1 addition & 1 deletion tests/data/Ref_NXnested_symbols.nxdl.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<!--
# NeXus - Neutron and X-ray Common Data Format
#
# Copyright (C) 2014-2022 NeXus International Advisory Committee (NIAC)
# Copyright (C) 2010-2020 NeXus International Advisory Committee (NIAC)
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
Expand Down
2 changes: 1 addition & 1 deletion tests/data/Ref_NXtest_links.nxdl.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<!--
# NeXus - Neutron and X-ray Common Data Format
#
# Copyright (C) 2014-2022 NeXus International Advisory Committee (NIAC)
# Copyright (C) 2010-2020 NeXus International Advisory Committee (NIAC)
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
Expand Down
2 changes: 1 addition & 1 deletion tests/data/dimensions.nxdl.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<!--
# NeXus - Neutron and X-ray Common Data Format
#
# Copyright (C) 2014-2024 NeXus International Advisory Committee (NIAC)
# Copyright (C) 2010-2020 NeXus International Advisory Committee (NIAC)
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
Expand Down
2 changes: 1 addition & 1 deletion tests/data/doc_nxdl2yaml.nxdl.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<!--
# NeXus - Neutron and X-ray Common Data Format
#
# Copyright (C) 2014-2023 NeXus International Advisory Committee (NIAC)
# Copyright (C) 2010-2020 NeXus International Advisory Committee (NIAC)
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
Expand Down
2 changes: 1 addition & 1 deletion tests/data/ref_dim_keyword.nxdl.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<!--
# NeXus - Neutron and X-ray Common Data Format
#
# Copyright (C) 2025-2025 NeXus International Advisory Committee (NIAC)
# Copyright (C) 2010-2020 NeXus International Advisory Committee (NIAC)
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
Expand Down
2 changes: 1 addition & 1 deletion tests/data/ref_doc_yaml2nxdl.nxdl.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<!--
# NeXus - Neutron and X-ray Common Data Format
#
# Copyright (C) 2014-2024 NeXus International Advisory Committee (NIAC)
# Copyright (C) 2010-2020 NeXus International Advisory Committee (NIAC)
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
Expand Down
2 changes: 1 addition & 1 deletion tests/data/ref_no_tabs_yaml2nxdl.nxdl.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<!--
# NeXus - Neutron and X-ray Common Data Format
#
# Copyright (C) 2014-2024 NeXus International Advisory Committee (NIAC)
# Copyright (C) 2010-2020 NeXus International Advisory Committee (NIAC)
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
Expand Down
25 changes: 23 additions & 2 deletions tests/test_nyaml2nxdl.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import filecmp
import os
import re
import sys
from datetime import datetime
from pathlib import Path
Expand All @@ -35,6 +36,24 @@
from nyaml.helper import LineLoader, remove_namespace_from_tag
from nyaml.nyaml2nxdl import handle_each_part_doc

LATEST_COPYRIGHT_YEAR = f"{datetime.now().year}-{datetime.now().year}"
LATEST_COPYRIGHT = rf"# Copyright \(C\) {LATEST_COPYRIGHT_YEAR} NeXus International Advisory Committee \(NIAC\)"
COPYRIGHT_REPLACEMENT = (
f"# Copyright (C) 2010-2020 NeXus International Advisory Committee (NIAC)"
)


def check_and_replace_latest_copyright(file):
"""Check if the latest copyright date has been written properly,
and replace it accordingly to the test data file.
"""
content = file.read_text()
generated_copyright = re.findall(LATEST_COPYRIGHT, content, re.DOTALL)
assert len(generated_copyright) == 1, (
f"No copyright or not correct copyright year found in {file}"
)
content = re.sub(LATEST_COPYRIGHT, COPYRIGHT_REPLACEMENT, content)
file.write_text(content)

def delete_duplicates(list_of_matching_string):
"""
Expand Down Expand Up @@ -435,7 +454,8 @@ def test_yaml2nxdl_doc():
if result.exit_code != 0:
Path.unlink(out_doc_file)
assert result.exit_code == 0, f"Error: Having issue running input file {doc_file}."

# Check copyright year and repalce it according to the ref file
check_and_replace_latest_copyright(out_doc_file)
ref_nxdl = ET.parse(str(ref_doc_file)).getroot()
out_nxdl = ET.parse(str(out_doc_file)).getroot()

Expand Down Expand Up @@ -500,6 +520,7 @@ def test_nyaml2nxdl_dim_keyword(tmp_path):
)

assert result.exit_code == 0, "Error in converter execution."
check_and_replace_latest_copyright(parsed_file)
assert ref_file.read_text() == parsed_file.read_text()


Expand Down Expand Up @@ -542,7 +563,7 @@ def test_yaml2nxdl_no_tabs(tmp_path):
nyaml2nxdl.launch_tool, [str(doc_file), "--output-file", str(out_doc_file)]
)
assert result.exit_code == 0, f"Error: Having issue running input file {doc_file}."

check_and_replace_latest_copyright(out_doc_file)
ref_nxdl = ET.parse(str(ref_doc_file)).getroot()
out_nxdl = ET.parse(str(out_doc_file)).getroot()

Expand Down

0 comments on commit 302ed12

Please sign in to comment.