Skip to content

Commit

Permalink
test case added
Browse files Browse the repository at this point in the history
  • Loading branch information
sanbrock committed Jun 19, 2023
1 parent b65bf23 commit 90a9e45
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 11 deletions.
24 changes: 14 additions & 10 deletions dev_tools/nyaml2nxdl/nyaml2nxdl.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,14 @@
import xml.etree.ElementTree as ET

import click
from pynxtools.nyaml2nxdl.nyaml2nxdl_backward_tools import Nxdl2yaml
from pynxtools.nyaml2nxdl.nyaml2nxdl_backward_tools import compare_niac_and_my
from pynxtools.nyaml2nxdl.nyaml2nxdl_forward_tools import nyaml2nxdl
from pynxtools.nyaml2nxdl.nyaml2nxdl_forward_tools import pretty_print_xml
from pynxtools.nyaml2nxdl.nyaml2nxdl_helper import extend_yamlfile_with_comment
from pynxtools.nyaml2nxdl.nyaml2nxdl_helper import get_sha256_hash
from pynxtools.nyaml2nxdl.nyaml2nxdl_helper import separate_hash_yaml_and_nxdl

from .nyaml2nxdl_backward_tools import Nxdl2yaml
from .nyaml2nxdl_backward_tools import compare_niac_and_my
from .nyaml2nxdl_forward_tools import nyaml2nxdl
from .nyaml2nxdl_forward_tools import pretty_print_xml
from .nyaml2nxdl_helper import extend_yamlfile_with_comment
from .nyaml2nxdl_helper import get_sha256_hash
from .nyaml2nxdl_helper import separate_hash_yaml_and_nxdl

DEPTH_SIZE = 4 * " "

Expand Down Expand Up @@ -152,15 +153,18 @@ def split_name_and_extension(file_name):
Split file name into extension and rest of the file name.
return file raw nam and extension
"""
parts = file_name.rsplit(".", 3)
path = file_name.rsplit("/", 1)
(pathn, filen) = ["", path[0]] if len(path) == 1 else [path[0] + "/", path[1]]
parts = filen.rsplit(".", 2)
raw = ext = ""
if len(parts) == 2:
raw = parts[0]
ext = parts[1]
if len(parts) == 3:
elif len(parts) == 3:
raw = parts[0]
ext = ".".join(parts[1:])

return raw, ext
return pathn + raw, ext


@click.command()
Expand Down
2 changes: 1 addition & 1 deletion dev_tools/nyaml2nxdl/nyaml2nxdl_forward_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
import yaml

from ..utils import nexus as pynxtools_nxlib
from .nyaml2nxdl.comment_collector import CommentCollector
from .comment_collector import CommentCollector
from .nyaml2nxdl_helper import LineLoader
from .nyaml2nxdl_helper import cleaning_empty_lines
from .nyaml2nxdl_helper import get_yaml_escape_char_reverter_dict
Expand Down
27 changes: 27 additions & 0 deletions dev_tools/tests/test_nyaml2nxdl.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import os

from click.testing import CliRunner

from ..nyaml2nxdl import nyaml2nxdl as conv
from ..utils.nexus import find_definition_file

# import subprocess


def test_conversion():
root = find_definition_file("NXentry")
# subprocess.run(["python3","-m","dev_tools.nyaml2nxdl.nyaml2nxdl","--input-file",root])
result = CliRunner().invoke(conv.launch_tool, ["--input-file", root])
assert result.exit_code == 0
yaml = root[:-9] + "_parsed.yaml"
# subprocess.run(["python3","-m","dev_tools.nyaml2nxdl.nyaml2nxdl","--input-file",yaml])
result = CliRunner().invoke(conv.launch_tool, ["--input-file", yaml])
assert result.exit_code == 0
new_root = yaml[:-4] + "nxdl.xml"
with open(root, encoding="utf-8", mode="r") as tmp_f:
root_content = tmp_f.readlines()
with open(new_root, encoding="utf-8", mode="r") as tmp_f:
new_root_content = tmp_f.readlines()
assert root_content == new_root_content
os.remove(yaml)
os.remove(new_root)

0 comments on commit 90a9e45

Please sign in to comment.