Script 'mail_helper' called by obssrc
Hello community,

here is the log from the commit of package python-sambacc for openSUSE:Factory 
checked in at 2023-05-10 16:20:10
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Comparing /work/SRC/openSUSE:Factory/python-sambacc (Old)
 and      /work/SRC/openSUSE:Factory/.python-sambacc.new.1533 (New)
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Package is "python-sambacc"

Wed May 10 16:20:10 2023 rev:3 rq:1086073 version:v0.2+git.108.e7850e0

Changes:
--------
--- /work/SRC/openSUSE:Factory/python-sambacc/python-sambacc.changes    
2023-04-19 17:42:52.588158494 +0200
+++ /work/SRC/openSUSE:Factory/.python-sambacc.new.1533/python-sambacc.changes  
2023-05-10 16:20:11.803568226 +0200
@@ -1,0 +2,25 @@
+Wed May 10 11:24:39 UTC 2023 - dmul...@suse.com
+
+- Update to version v0.2+git.108.e7850e0:
+  * docs: document the availability of yaml and toml formatted confs
+  * extras: have rpm spec recommend extras on fedora 37 & later
+  * extras: add our toml and yaml extras to the rpm spec
+  * tox: get all test envs that install via pip working with extras
+  * setup: add extras for toml and yaml
+  * tests: support testing toml with tomli or tomllib
+  * sambacc: support tomli for reading toml on older versions
+  * tests: add test cases for yaml formatted configuration
+  * sambacc: add support for reading YAML formatted configs
+  * tests: add test cases for toml formatted configuration
+  * sambacc: add support for reading TOML formatted configs
+  * copr: add .copr/Makefile for building in COPR system
+  * container: default to dnf in build script
+  * container: more granular controls of build script behavior
+  * container: generate a more robust rpm spec file
+  * container: make build script a tad more consistent
+  * extras: fix a typo in the rpm spec
+  * extras: add additional build deps to the rpm spec file
+  * extras: add validation extra as an rpm sub package
+  * sambacc: make config module robust to unexpected jsonschema versions
+
+-------------------------------------------------------------------

Old:
----
  sambacc-v0.2+git.88.c81c65a.tar.bz2

New:
----
  sambacc-v0.2+git.108.e7850e0.tar.bz2

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Other differences:
------------------
++++++ python-sambacc.spec ++++++
--- /var/tmp/diff_new_pack.ZG8zKy/_old  2023-05-10 16:20:12.403571775 +0200
+++ /var/tmp/diff_new_pack.ZG8zKy/_new  2023-05-10 16:20:12.411571822 +0200
@@ -19,7 +19,7 @@
 %global bname sambacc
 
 Name:           python-%{bname}
-Version:        v0.2+git.88.c81c65a
+Version:        v0.2+git.108.e7850e0
 Release:        0
 Summary:        Samba Container Configurator
 License:        GPL-3.0-or-later

++++++ _servicedata ++++++
--- /var/tmp/diff_new_pack.ZG8zKy/_old  2023-05-10 16:20:12.459572106 +0200
+++ /var/tmp/diff_new_pack.ZG8zKy/_new  2023-05-10 16:20:12.467572153 +0200
@@ -1,7 +1,7 @@
 <servicedata>
  <service name="tar_scm">
   <param name="url">https://github.com/samba-in-kubernetes/sambacc.git</param>
-  <param 
name="changesrevision">c81c65aa610250b163a42cfd8d172268578623f0</param>
+  <param 
name="changesrevision">e7850e076664f35f7ef62a8792939cf48ef8e0a7</param>
  </service>
 </servicedata>
 (No newline at EOF)

++++++ sambacc-v0.2+git.88.c81c65a.tar.bz2 -> 
sambacc-v0.2+git.108.e7850e0.tar.bz2 ++++++
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/sambacc-v0.2+git.88.c81c65a/.copr/Makefile 
new/sambacc-v0.2+git.108.e7850e0/.copr/Makefile
--- old/sambacc-v0.2+git.88.c81c65a/.copr/Makefile      1970-01-01 
01:00:00.000000000 +0100
+++ new/sambacc-v0.2+git.108.e7850e0/.copr/Makefile     2023-04-25 
11:56:38.000000000 +0200
@@ -0,0 +1,29 @@
+
+
+SELF=$(lastword $(MAKEFILE_LIST))
+ROOT_DIR=$(abspath $(dir $(SELF))/..)
+SKIP_DEPS=
+
+outdir:=/var/tmp/copr-tmp-outdir
+spec:=extras/python-sambacc.spec
+
+.PHONY: srpm
+srpm: sys_deps
+       mkdir -p $(outdir)
+       git fetch --tags
+       SAMBACC_SRPM_ONLY=yes \
+               SAMBACC_BUILD_DIR=$(ROOT_DIR) \
+               SAMBACC_DIST_PREFIX=$(outdir)/.dist \
+               SAMBACC_DISTNAME=copr \
+               SAMBACC_BUILD_TASKS="task_py_build task_rpm_build" \
+                ./tests/container/build.sh
+       cp $(outdir)/.dist/copr/SRPMS/*.rpm  $(outdir)
+
+
+.PHONY: sys_deps
+sys_deps:
+ifeq ($(SKIP_DEPS),yes)
+       @echo "Skipping sys deps"
+else
+       dnf install -y python3-pip git
+endif
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/sambacc-v0.2+git.88.c81c65a/docs/configuration.md 
new/sambacc-v0.2+git.108.e7850e0/docs/configuration.md
--- old/sambacc-v0.2+git.88.c81c65a/docs/configuration.md       2023-04-18 
17:22:39.000000000 +0200
+++ new/sambacc-v0.2+git.108.e7850e0/docs/configuration.md      2023-04-25 
11:56:38.000000000 +0200
@@ -1,10 +1,15 @@
 
 # JSON Configuration Format
 
-Much of the behavior of sambacc is driven by the JSON based
-configuration file. The following is a high level example of the JSON
+Much of the behavior of sambacc is driven by the
+configuration files. The following is a high level example of the JSON
 structure and a description of these sections.
 
+If sambacc is installed with the `yaml` extra it can support [YAML](#yaml)
+based configuration files. If sambacc is installed with the `toml` extra it can
+support [TOML](#toml) based configuration files. The JSON support is the
+default and is always present.
+
 ```json
 {
     "samba-container-config": "v0",
@@ -278,3 +283,98 @@
 * `password` - A plain-text password.
 * `member_of` - Optional. List of group names. The user will be added to the 
listed
   groups.
+
+
+# YAML
+
+The [YAML](https://yaml.org/) format may be used to configure sambacc when
+PyYAML library is available. The YAML configuration is effectively converted to
+JSON internally when processed. All of the documentation applying to the JSON
+based configuration applies but in a somewhat easier to write format. The
+filename must end with `.yaml` or `.yml` for sambacc to parse the file as YAML.
+
+An example of a YAML based configuration file:
+```yaml
+samba-container-config: v0
+# Define top-level configurations
+configs:
+  try2:
+    globals: ["default"]
+    shares:
+      - "example"
+      - "Other Name"
+# Define Global Options
+globals:
+  default:
+    options:
+      load printers: "no"
+      printing: "bsd"
+      printcap name: "/dev/null"
+      disable spoolss: "yes"
+      guest ok: "no"
+      security: "user"
+      server min protocol: "SMB2"
+# Define Shares
+shares:
+  example:
+    options:
+      path: /srv/a
+      read only: "no"
+  Other Name:
+    options:
+      path: /srv/b
+      read only: "no"
+# Define users
+users:
+  all_entries:
+    - {"name": "sambauser", "password": "samba"}
+    - {"name": "otheruser", "password": "insecure321"}
+```
+
+# TOML
+
+The [TOML](https://toml.io/en/) format may be used to configure sambacc when
+used on Python 3.11 or later or when the tomli library is available. The TOML
+format may seem similar to the INI-style format used by Samba.  The TOML
+configuration is effectively converted to JSON internally when processed. All
+of the documentation applying to the JSON based configuration applies but in a
+somewhat easier to read and write format. The filename must end with `.toml` 
for
+sambacc to parse the file as TOML.
+
+An example of a TOML based configuration file:
+```toml
+samba-container-config = "v0"
+
+# Define top level configurations
+[configs.try1]
+globals = ["default"]
+shares = ["example", "Other Name"]
+
+# Define shares
+[shares.example.options]
+path = "/srv/a"
+"read only" = "no"
+
+[shares."Other Name".options]
+path = "/srv/b"
+"read only" = "no"
+
+# Define global options
+[globals.default.options]
+"load printers" = "no"
+printing = "bsd"
+"printcap name" = "/dev/null"
+"disable spoolss" = "yes"
+"guest ok" = "no"
+security = "user"
+"server min protocol" = "SMB2"
+
+# Define users
+[[users.all_entries]]
+name = "sambauser"
+password = "samba"
+
+[[users.all_entries]]
+name = "otheruser"
+password = "insecure321"
+```
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' 
old/sambacc-v0.2+git.88.c81c65a/extras/python-sambacc.spec 
new/sambacc-v0.2+git.108.e7850e0/extras/python-sambacc.spec
--- old/sambacc-v0.2+git.88.c81c65a/extras/python-sambacc.spec  2023-04-18 
17:22:39.000000000 +0200
+++ new/sambacc-v0.2+git.108.e7850e0/extras/python-sambacc.spec 2023-04-25 
11:56:38.000000000 +0200
@@ -20,6 +20,11 @@
 
 BuildArch:      noarch
 BuildRequires:  python3-devel
+# we need python3-samba as a build dependency in order to run
+# the test suite
+BuildRequires:  python3-samba
+# ditto for the net binary
+BuildRequires: /usr/bin/net
 
 %global _description %{expand:
 A Python library and set of CLI tools intended to act as a bridge between a 
container
@@ -32,9 +37,14 @@
 
 %package -n python3-%{bname}
 Summary: %{summary}
-# Distro requires that are technially optional for the lib
+# Distro requires that are technically optional for the lib
 Requires: python3-samba
 Requires: python3-pyxattr
+%if 0%{?fedora} >= 37
+Recommends: %{name}+toml
+Recommends: %{name}+validation
+Recommends: %{name}+yaml
+%endif
 
 %description -n python3-%{bname}  %_description
 
@@ -66,5 +76,10 @@
 %{_datadir}/%{bname}/examples/
 
 
+%pyproject_extras_subpkg -n python3-%{bname} validation
+%pyproject_extras_subpkg -n python3-%{bname} toml
+%pyproject_extras_subpkg -n python3-%{bname} yaml
+
+
 %changelog
 %autochangelog
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/sambacc-v0.2+git.88.c81c65a/sambacc/config.py 
new/sambacc-v0.2+git.108.e7850e0/sambacc/config.py
--- old/sambacc-v0.2+git.88.c81c65a/sambacc/config.py   2023-04-18 
17:22:39.000000000 +0200
+++ new/sambacc-v0.2+git.108.e7850e0/sambacc/config.py  2023-04-25 
11:56:38.000000000 +0200
@@ -19,8 +19,10 @@
 from __future__ import annotations
 
 import binascii
+import enum
 import errno
 import json
+import sys
 import typing
 
 _VALID_VERSIONS = ["v0"]
@@ -48,15 +50,70 @@
 _JSON_SCHEMA: dict[str, typing.Any] = {}
 
 
+class ConfigFormat(enum.Enum):
+    JSON = "json"
+    TOML = "toml"
+    YAML = "yaml"
+
+
 class ValidationUnsupported(Exception):
     pass
 
 
+class _FakeRefResolutionError(Exception):
+    pass
+
+
+class ConfigFormatUnsupported(Exception):
+    pass
+
+
+if sys.version_info >= (3, 11):
+
+    def _load_toml(source: typing.IO) -> JSONData:
+        try:
+            import tomllib
+        except ImportError:
+            raise ConfigFormatUnsupported(ConfigFormat.TOML)
+        return tomllib.load(source)
+
+else:
+
+    def _load_toml(source: typing.IO) -> JSONData:
+        try:
+            import tomli
+        except ImportError:
+            raise ConfigFormatUnsupported(ConfigFormat.TOML)
+        if typing.TYPE_CHECKING:
+            assert isinstance(source, typing.BinaryIO)
+        return tomli.load(source)
+
+
+def _load_yaml(source: typing.IO) -> JSONData:
+    try:
+        import yaml
+    except ImportError:
+        raise ConfigFormatUnsupported(ConfigFormat.YAML)
+    return yaml.safe_load(source) or {}
+
+
+def _detect_format(fname: str) -> ConfigFormat:
+    if fname.endswith(".toml"):
+        return ConfigFormat.TOML
+    if fname.endswith((".yaml", ".yml")):
+        return ConfigFormat.YAML
+    return ConfigFormat.JSON
+
+
 def _schema_validate(data: dict[str, typing.Any], version: str) -> None:
     try:
         import jsonschema  # type: ignore[import]
     except ImportError:
         raise ValidationUnsupported()
+    try:
+        _refreserror = getattr(jsonschema, "RefResolutionError")
+    except AttributeError:
+        _refreserror = _FakeRefResolutionError
 
     global _JSON_SCHEMA
     if version == "v0" and version not in _JSON_SCHEMA:
@@ -66,7 +123,10 @@
             _JSON_SCHEMA[version] = sambacc.schema.conf_v0_schema.SCHEMA
         except ImportError:
             raise ValidationUnsupported()
-    jsonschema.validate(instance=data, schema=_JSON_SCHEMA[version])
+    try:
+        jsonschema.validate(instance=data, schema=_JSON_SCHEMA[version])
+    except _refreserror:
+        raise ValidationUnsupported()
 
 
 def _check_config_version(data: JSONData) -> str:
@@ -108,9 +168,14 @@
     gconfig = GlobalConfig()
     readfiles = set()
     for fname in fnames:
+        config_format = _detect_format(str(fname))
         try:
-            with _open(fname) as fh:
-                gconfig.load(fh, require_validation=require_validation)
+            with _open(fname, "rb") as fh:
+                gconfig.load(
+                    fh,
+                    require_validation=require_validation,
+                    config_format=config_format,
+                )
             readfiles.add(fname)
         except OSError as err:
             if getattr(err, "errno", 0) != errno.ENOENT:
@@ -143,9 +208,17 @@
     def load(
         self,
         source: typing.IO,
+        *,
         require_validation: typing.Optional[bool] = None,
+        config_format: typing.Optional[ConfigFormat] = None,
     ) -> None:
-        data = json.load(source)
+        config_format = config_format or ConfigFormat.JSON
+        if config_format == ConfigFormat.TOML:
+            data = _load_toml(source)
+        elif config_format == ConfigFormat.YAML:
+            data = _load_yaml(source)
+        else:
+            data = json.load(source)
         _check_config_valid(
             data, _check_config_version(data), require_validation
         )
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/sambacc-v0.2+git.88.c81c65a/setup.cfg 
new/sambacc-v0.2+git.108.e7850e0/setup.cfg
--- old/sambacc-v0.2+git.88.c81c65a/setup.cfg   2023-04-18 17:22:39.000000000 
+0200
+++ new/sambacc-v0.2+git.108.e7850e0/setup.cfg  2023-04-25 11:56:38.000000000 
+0200
@@ -31,3 +31,7 @@
 [options.extras_require]
 validation =
     jsonschema>=4.10
+yaml =
+    PyYAML>=5.4
+toml =
+    tomli;python_version<"3.11"
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/sambacc-v0.2+git.88.c81c65a/tests/container/build.sh 
new/sambacc-v0.2+git.108.e7850e0/tests/container/build.sh
--- old/sambacc-v0.2+git.88.c81c65a/tests/container/build.sh    2023-04-18 
17:22:39.000000000 +0200
+++ new/sambacc-v0.2+git.108.e7850e0/tests/container/build.sh   2023-04-25 
11:56:38.000000000 +0200
@@ -4,10 +4,12 @@
 
 python=python3
 url="https://github.com/samba-in-kubernetes/sambacc";
-bdir="/var/tmp/build/sambacc"
+bdir="${SAMBACC_BUILD_DIR:-/var/tmp/build/sambacc}"
 distname="${SAMBACC_DISTNAME}"
 # use SAMBACC_BUILD_TASKS to limit build tasks if needed
 tasks="${SAMBACC_BUILD_TASKS:-task_test_tox task_py_build task_rpm_build 
task_gen_sums}"
+dist_prefix="${SAMBACC_DIST_PREFIX:-/srv/dist}"
+dnf_cmd=dnf
 
 info() {
     echo "[[sambacc/build]] $*"
@@ -51,7 +53,7 @@
 get_distdir() {
     dname="$1"
     if [ "${dname}" ]; then
-        ddir="/srv/dist/$dname"
+        ddir="${dist_prefix}/$dname"
     else
         ddir="/var/tmp/scratch_dist"
     fi
@@ -128,12 +130,12 @@
     )
 
     if [ "$use_centos" ]; then
-        yum install -y epel-release
+        "${dnf_cmd}" install -y epel-release
         yum_args=(--enablerepo=crb)
         pkgs+=(pyproject-rpm-macros)
     fi
-    yum "${yum_args[@]}" install -y "${pkgs[@]}"
-    yum clean all
+    "${dnf_cmd}" "${yum_args[@]}" install -y "${pkgs[@]}"
+    "${dnf_cmd}" clean all
 }
 
 task_test_tox() {
@@ -167,7 +169,11 @@
     fi
 
     distdir="$(get_distdir "$distname")"
-    info "using dist dir: $distdir"
+    local rpmbuild_stage="-ba"
+    if [ "${SAMBACC_SRPM_ONLY}" ]; then
+        rpmbuild_stage="-bs"
+    fi
+    info "using dist dir: $distdir; using stage: ${rpmbuild_stage}"
     for spkg in "$distdir/sambacc"-*.tar.gz; do
         info "RPM build for: ${spkg}"
         ver="$(basename  "${spkg}" | sed -e 's/^sambacc-//' -e 's/.tar.gz$//')"
@@ -177,11 +183,19 @@
             rversion="$ver"
         fi
         info "Using rpm-version=${rversion} pkg-version=${ver}"
-        rpmbuild --nocheck -ta \
-            -D "pversion ${ver}" -D"rversion ${rversion}" \
+        tdir="$(mktemp -d)"
+        (
+            echo "%define pversion ${ver}"
+            echo "%define rversion ${rversion}"
+            tar -xf "$spkg" -O \
+                "sambacc-${ver}/extras/python-sambacc.spec"
+        ) > "${tdir}/python-sambacc.spec"
+        rpmbuild "${rpmbuild_stage}" \
             -D "_rpmdir ${distdir}/RPMS" \
             -D "_srcrpmdir ${distdir}/SRPMS" \
-            "$spkg"
+            -D "_sourcedir $(dirname "${spkg}")" \
+            "${tdir}/python-sambacc.spec"
+        rm -rf "${tdir}"
     done
 }
 
@@ -203,6 +217,10 @@
     fi
 }
 
+if ! command -v "${dnf_cmd}" >/dev/null ; then
+    dnf_cmd=yum
+fi
+
 # Allow the tests to use customized passwd file contents in order
 # to test samba passdb support. It's a bit strange, but should work.
 # The test suite tries to restore the passwd file after changing it,
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/sambacc-v0.2+git.88.c81c65a/tests/test_config.py 
new/sambacc-v0.2+git.108.e7850e0/tests/test_config.py
--- old/sambacc-v0.2+git.88.c81c65a/tests/test_config.py        2023-04-18 
17:22:39.000000000 +0200
+++ new/sambacc-v0.2+git.108.e7850e0/tests/test_config.py       2023-04-25 
11:56:38.000000000 +0200
@@ -448,7 +448,7 @@
 
 
 def test_tesd_config_files_realerr_rootok(monkeypatch):
-    def err_open(p):
+    def err_open(*args):
         raise OSError("test!")
 
     monkeypatch.setattr(sambacc.config, "_open", err_open)
@@ -756,6 +756,23 @@
     assert "friendship" in opts
 
 
+def _can_import_toml():
+    """Return true if one valid toml module can be imported.
+    Work around importorskip only supporting one module name.
+    """
+    try:
+        __import__("tomllib")
+        return True
+    except ImportError:
+        pass
+    try:
+        __import__("tomli")
+        return True
+    except ImportError:
+        pass
+    return False
+
+
 @pytest.mark.parametrize(
     "json_str,ok",
     [
@@ -912,3 +929,342 @@
     else:
         with pytest.raises((ValueError, jsonschema.ValidationError)):
             cfg.load(io.StringIO(json_str), require_validation=True)
+
+
+@pytest.mark.parametrize(
+    "toml_str,ok",
+    [
+        pytest.param("", False, id="empty"),
+        pytest.param("#####FOO", False, id="just-a-comment"),
+        pytest.param(
+            """
+samba-container-config = "v0"
+""",
+            True,
+            id="minimal",
+        ),
+        pytest.param(
+            """
+samba-container-config = "v0"
+
+# Define configurations
+[configs.foobar]
+shares = ["foobar"]
+
+# Define share options
+[shares.foobar.options]
+a = "b"
+""",
+            True,
+            id="one-share",
+        ),
+    ],
+)
+@pytest.mark.skipif(not _can_import_toml(), reason="no toml module")
+def test_toml_configs_no_validation(toml_str, ok):
+    cfg = sambacc.config.GlobalConfig()
+    fh = io.BytesIO(toml_str.encode("utf8"))
+    if ok:
+        cfg.load(
+            fh,
+            require_validation=False,
+            config_format=sambacc.config.ConfigFormat.TOML,
+        )
+    else:
+        with pytest.raises(ValueError):
+            cfg.load(
+                fh,
+                require_validation=False,
+                config_format=sambacc.config.ConfigFormat.TOML,
+            )
+
+
+@pytest.mark.parametrize(
+    "toml_str,ok",
+    [
+        pytest.param("", False, id="empty"),
+        pytest.param("#####FOO", False, id="just-a-comment"),
+        pytest.param(
+            """
+samba-container-config = "v0"
+""",
+            True,
+            id="minimal",
+        ),
+        pytest.param(
+            """
+samba-container-config = "v0"
+
+# Define configurations
+[configs.foobar]
+shares = ["foobar"]
+
+# Define share options
+[shares.foobar.options]
+a = "b"
+""",
+            True,
+            id="one-share",
+        ),
+        pytest.param(
+            """
+samba-container-config = "v0"
+
+# Define configurations
+[configs.foobar]
+shares = ["foobar"]
+instance_features = "Kibbe"
+
+# Define share options
+[shares.foobar.options]
+a = "b"
+""",
+            False,
+            id="bad-instance_features",
+        ),
+        pytest.param(
+            """
+samba-container-config = "v0"
+
+# Define configurations
+[configs.foobar]
+shares = ["foobar"]
+instance_features = ["ctdb"]
+
+# Define share options
+[shares.foobar.options]
+a = "b"
+""",
+            True,
+            id="ok-instance_features",
+        ),
+        pytest.param(
+            """
+samba-container-config = "v0"
+
+[configs.demo]
+shares = ["share"]
+globals = ["default"]
+instance_features = ["ctdb"]
+instance_name = "SAMBA"
+
+[shares.share.options]
+"path" = "/share"
+"read only" = "no"
+"valid users" = "sambauser, otheruser"
+
+[globals.default.options]
+"security" = "user"
+"server min protocol" = "SMB2"
+"load printers" = "no"
+"printing" = "bsd"
+"printcap name" = "/dev/null"
+"disable spoolss" = "yes"
+"guest ok" = "no"
+
+[[users.all_entries]]
+name = "sambauser"
+password = "samba"
+
+[[users.all_entries]]
+name = "otheruser"
+password = "insecure321"
+""",
+            True,
+            id="complex",
+        ),
+    ],
+)
+@pytest.mark.skipif(not _can_import_toml(), reason="no toml module")
+def test_toml_configs_validation(toml_str, ok):
+    jsonschema = pytest.importorskip("jsonschema")
+
+    cfg = sambacc.config.GlobalConfig()
+    fh = io.BytesIO(toml_str.encode("utf8"))
+    if ok:
+        cfg.load(
+            fh,
+            require_validation=True,
+            config_format=sambacc.config.ConfigFormat.TOML,
+        )
+    else:
+        with pytest.raises((ValueError, jsonschema.ValidationError)):
+            cfg.load(
+                fh,
+                require_validation=True,
+                config_format=sambacc.config.ConfigFormat.TOML,
+            )
+
+
+@pytest.mark.parametrize(
+    "yaml_str,ok",
+    [
+        pytest.param("", False, id="empty"),
+        pytest.param("#####FOO", False, id="just-a-comment"),
+        pytest.param(
+            """
+samba-container-config: "v0"
+""",
+            True,
+            id="minimal",
+        ),
+        pytest.param(
+            """
+samba-container-config: "v0"
+# Define configurations
+configs:
+  foobar:
+    shares:
+      - foobar
+shares:
+  foobar:
+    options:
+      a: b
+""",
+            True,
+            id="one-share",
+        ),
+    ],
+)
+def test_yaml_configs_no_validation(yaml_str, ok):
+    pytest.importorskip("yaml")
+
+    cfg = sambacc.config.GlobalConfig()
+    fh = io.BytesIO(yaml_str.encode("utf8"))
+    if ok:
+        cfg.load(
+            fh,
+            require_validation=False,
+            config_format=sambacc.config.ConfigFormat.YAML,
+        )
+    else:
+        with pytest.raises(ValueError):
+            cfg.load(
+                fh,
+                require_validation=False,
+                config_format=sambacc.config.ConfigFormat.YAML,
+            )
+
+
+@pytest.mark.parametrize(
+    "yaml_str,ok",
+    [
+        pytest.param("", False, id="empty"),
+        pytest.param("#####FOO", False, id="just-a-comment"),
+        pytest.param(
+            """
+samba-container-config: v0
+""",
+            True,
+            id="minimal",
+        ),
+        pytest.param(
+            """
+samba-container-config: v0
+# Define configurations
+configs:
+  foobar:
+    shares:
+      - foobar
+# Define shares
+shares:
+  foobar:
+    options:
+      a: b
+""",
+            True,
+            id="one-share",
+        ),
+        pytest.param(
+            """
+samba-container-config: v0
+configs:
+  foobar:
+    instance_features: baroof
+    shares:
+      - foobar
+shares:
+  foobar:
+    options:
+      a: b
+""",
+            False,
+            id="bad-instance_features",
+        ),
+        pytest.param(
+            """
+samba-container-config: v0
+configs:
+  foobar:
+    instance_features:
+      - ctdb
+    shares:
+      - foobar
+shares:
+  foobar:
+    options:
+      a: b
+""",
+            True,
+            id="ok-instance_features",
+        ),
+        pytest.param(
+            """
+samba-container-config: "v0"
+# Configure our demo instance
+configs:
+  demo:
+    shares: ["share"]
+    globals: ["default"]
+    instance_features: ["ctdb"]
+    instance_name: "SAMBA"
+# Configure the share
+shares:
+  share:
+    options:
+      "path": "/share"
+      "read only": "no"
+      "valid users": "sambauser, otheruser"
+# Configure globals
+globals:
+  default:
+    options:
+      "security": "user"
+      "server min protocol": "SMB2"
+      "load printers": "no"
+      "printing": "bsd"
+      "printcap name": "/dev/null"
+      "disable spoolss": "yes"
+      "guest ok": "no"
+# Configure users
+users:
+  all_entries:
+    - {"name": "sambauser", "password": "samba"}
+    - {"name": "otheruser", "password": "insecure321"}
+    - name: cooluser
+      password: snarf
+""",
+            True,
+            id="complex",
+        ),
+    ],
+)
+def test_yaml_configs_validation(yaml_str, ok):
+    pytest.importorskip("yaml")
+    jsonschema = pytest.importorskip("jsonschema")
+
+    cfg = sambacc.config.GlobalConfig()
+    fh = io.BytesIO(yaml_str.encode("utf8"))
+    if ok:
+        cfg.load(
+            fh,
+            require_validation=True,
+            config_format=sambacc.config.ConfigFormat.YAML,
+        )
+    else:
+        with pytest.raises((ValueError, jsonschema.ValidationError)):
+            cfg.load(
+                fh,
+                require_validation=True,
+                config_format=sambacc.config.ConfigFormat.YAML,
+            )
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/sambacc-v0.2+git.88.c81c65a/tox.ini 
new/sambacc-v0.2+git.108.e7850e0/tox.ini
--- old/sambacc-v0.2+git.88.c81c65a/tox.ini     2023-04-18 17:22:39.000000000 
+0200
+++ new/sambacc-v0.2+git.108.e7850e0/tox.ini    2023-04-25 11:56:38.000000000 
+0200
@@ -12,7 +12,7 @@
     pytest
     pytest-cov
     dnspython
-    -e .[validation]
+    -e .[validation,yaml,toml]
 commands =
     py.test -v tests --cov=sambacc --cov-report=html {posargs}
 
@@ -22,6 +22,7 @@
     types-setuptools
     types-pyyaml
     types-jsonschema>=4.10
+    tomli
     {[testenv]deps}
 commands =
     mypy sambacc tests

Reply via email to