From 2e85870c871c4984d82607855eabf4612c011308 Mon Sep 17 00:00:00 2001 From: Anna Schumaker Date: Tue, 7 Nov 2023 15:13:09 -0500 Subject: [PATCH] list: Don't show empty xunits or tags Up until now, we've been appending an extra column to the listed output but allowing it to have empty entries. I'm changing this to filter out NULL entries, since it turns out that's what I want when I use the --tags option. I also updated the --xunits option to be consistent. Signed-off-by: Anna Schumaker --- tests/test_list.py | 15 +++++++-------- xfstestsdb/list.py | 4 ++++ 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/tests/test_list.py b/tests/test_list.py index 4f80ed1..b2686c7 100644 --- a/tests/test_list.py +++ b/tests/test_list.py @@ -30,6 +30,7 @@ class TestList(unittest.TestCase): self.xfstestsdb.run(["tag", "1", "mytag1"]) self.xfstestsdb.run(["tag", "1", "mytag2"]) self.xfstestsdb.run(["tag", "3", "mytag3"]) + self.xfstestsdb.run(["tag", "3", "othertag"]) self.xfstestsdb.sql.executemany("""UPDATE xfstests_runs SET timestamp=? WHERE rowid=?""", (timestamp, 1), @@ -116,13 +117,12 @@ class TestList(unittest.TestCase): self.xfstestsdb.run(["list", "--color", "none", "--tags"]) self.assertEqual(mock_stdout.getvalue(), """ -+-----+---------------------+-----------+---------------+ -| run | timestamp | device | tags | -+-----+---------------------+-----------+---------------+ -| 1 | 2023-01-01 12:59:59 | /dev/vda1 | mytag1,mytag2 | -| 2 | 2023-01-02 12:59:59 | /dev/vda2 | | -| 3 | 2023-01-03 12:59:59 | /dev/vdb1 | mytag3 | -+-----+---------------------+-----------+---------------+ ++-----+---------------------+-----------+-----------------+ +| run | timestamp | device | tags | ++-----+---------------------+-----------+-----------------+ +| 1 | 2023-01-01 12:59:59 | /dev/vda1 | mytag1,mytag2 | +| 3 | 2023-01-03 12:59:59 | /dev/vdb1 | mytag3,othertag | ++-----+---------------------+-----------+-----------------+ """) @unittest.mock.patch("sys.stdout", new_callable=io.StringIO) @@ -170,7 +170,6 @@ class TestList(unittest.TestCase): | run | timestamp | device | xunits | +-----+---------------------+-----------+---------------+ | 1 | 2023-01-01 12:59:59 | /dev/vda1 | test-1,test-2 | -| 2 | 2023-01-02 12:59:59 | /dev/vda2 | | | 3 | 2023-01-03 12:59:59 | /dev/vdb1 | test-3 | +-----+---------------------+-----------+---------------+ """) diff --git a/xfstestsdb/list.py b/xfstestsdb/list.py index e224c5b..efd9662 100644 --- a/xfstestsdb/list.py +++ b/xfstestsdb/list.py @@ -52,6 +52,8 @@ class Command(commands.Command): if isinstance(args.tags, str): filter.append("tag GLOB ?") sql_args.append(args.tags) + else: + filter.append("tag IS NOT NULL") if args.timestamp: filter.append("timestamp GLOB ?") @@ -62,6 +64,8 @@ class Command(commands.Command): if isinstance(args.xunits, str): filter.append("xunit GLOB ?") sql_args.append(args.xunits) + else: + filter.append("xunit IS NOT NULL") if len(filter) > 0: sql_where = " WHERE " + " AND ".join(filter) + " "