[osinfo-db-tools PATCH 4/7] tests: Add osinfo-db-path tests

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Add a set of functional tests to ensure osinfo-db-path works as
expected. The covered scenarios are:
- osinfo-db-path --system
- osinfo-db-path --local
- osinfo-db-oath --user
- osinfo-db-path --dir
- osinfo-db-path --root ROOT --system

https://gitlab.com/libosinfo/osinfo-db-tools/issues/2

Signed-off-by: Fabiano Fidêncio <fidencio@xxxxxxxxxx>
---
 .gitignore                   |  2 ++
 tests/Makefile.am            |  5 ++-
 tests/test_osinfo_db_path.py | 70 ++++++++++++++++++++++++++++++++++++
 3 files changed, 76 insertions(+), 1 deletion(-)
 create mode 100755 tests/test_osinfo_db_path.py

diff --git a/.gitignore b/.gitignore
index 8981135..27cea41 100644
--- a/.gitignore
+++ b/.gitignore
@@ -32,6 +32,8 @@ stamp-h1
 *.spec
 build/
 tests/*.log
+tests/*.trs
+tests/__pycache__
 tools/osinfo-db-validate
 tools/osinfo-db-validate.exe
 tools/osinfo-db-validate.1
diff --git a/tests/Makefile.am b/tests/Makefile.am
index ba267ad..16b760b 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -5,6 +5,7 @@ test_helpers = \
 	$(NULL)
 
 test_programs = \
+	test_osinfo_db_path.py \
 	$(NULL)
 
 EXTRA_DIST += \
@@ -18,4 +19,6 @@ TESTS = \
 
 TESTS_ENVIRONMENT = \
 	abs_top_builddir="$(abs_top_builddir)" \
-	abs_top_srcdir="$(abs_top_srcdir)"
+	abs_top_srcdir="$(abs_top_srcdir)" \
+	datadir="$(datadir)" \
+	sysconfdir="$(sysconfdir)"
diff --git a/tests/test_osinfo_db_path.py b/tests/test_osinfo_db_path.py
new file mode 100755
index 0000000..51fa787
--- /dev/null
+++ b/tests/test_osinfo_db_path.py
@@ -0,0 +1,70 @@
+#!/usr/bin/env python3
+#
+# This work is licensed under the GNU GPLv2 or later.
+# See the COPYING file in the top-level directory.
+
+import os
+import pytest
+import sys
+import util
+
+
+DATADIR = os.environ.get("datadir")
+SYSCONFDIR = os.environ.get("sysconfdir")
+FOOBAR_DIR = "/foo/bar"
+
+
+def test_osinfo_db_path_system():
+    """
+    Test osinfo-db-path --system
+    """
+    cmd = [util.Tools.db_path, util.ToolsArgs.SYSTEM]
+    output = util.get_output(cmd)
+    expected_output = os.path.join(DATADIR, "osinfo\n")
+    assert output == expected_output
+
+
+def test_osinfo_db_path_local():
+    """
+    Test osinfo-db-path --local
+    """
+    cmd = [util.Tools.db_path, util.ToolsArgs.LOCAL]
+    output = util.get_output(cmd)
+    expected_output = os.path.join(SYSCONFDIR, "osinfo\n")
+    assert output == expected_output
+
+
+def test_osinfo_db_path_user():
+    """
+    Test osinfo-db-path --user
+    """
+    cmd = [util.Tools.db_path, util.ToolsArgs.USER]
+    output = util.get_output(cmd)
+    expected_output = os.path.join(os.environ["HOME"], ".config",
+            "osinfo\n")
+    assert output == expected_output
+
+
+def test_osinfo_db_path_dir():
+    """
+    Test osinfo-db-path --dir
+    """
+    cmd = [util.Tools.db_path, util.ToolsArgs.DIR, FOOBAR_DIR]
+    output = util.get_output(cmd)
+    expected_output = FOOBAR_DIR + "\n"
+    assert output == expected_output
+
+
+def test_osinfo_db_path_root():
+    """
+    Test osinfo-db-path --root FOOBAR_DIR --system
+    """
+    cmd = [util.Tools.db_path, util.ToolsArgs.ROOT, FOOBAR_DIR,
+            util.ToolsArgs.SYSTEM]
+    output = util.get_output(cmd)
+    expected_output = os.path.join(FOOBAR_DIR, *DATADIR.split("/"), "osinfo\n")
+    assert output == expected_output
+
+
+if __name__ == "__main__":
+    exit(pytest.main(sys.argv))
-- 
2.21.0

_______________________________________________
Libosinfo mailing list
Libosinfo@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libosinfo




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Fedora Users]     [Fedora Maintainers]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]

  Powered by Linux