aiee

Python modules for common command line interfacing utils
git clone git://git.defalsify.org/aiee.git
Log | Files | Refs | LICENSE

commit 5bd8792f6050ce43b9c002f7c7780b04fccd498b
parent d59f467b1d8400783a0c7537302a609755a98046
Author: lash <dev@holbrook.no>
Date:   Wed, 11 May 2022 16:55:02 +0000

Accept comparison value to arg test match

Diffstat:
Maiee/arg.py | 11++++++++---
Mtests/test_arg.py | 17+++++++++++------
2 files changed, 19 insertions(+), 9 deletions(-)

diff --git a/aiee/arg.py b/aiee/arg.py @@ -190,9 +190,14 @@ class Arg: return self.__flags.get(k) - def match(self, v): - v = self.__flags.val(v) - return v & self.__z == v + def match(self, k, v_cmp): + k = to_key(k) + v = self.__flags.val(k) + import sys + sys.stderr.write('>>> {} {} {}\n'.format(k, v, self.__z)) + if v == 0: + return False + return (v & self.__z & v_cmp) == v def __iter__(self): diff --git a/tests/test_arg.py b/tests/test_arg.py @@ -259,14 +259,19 @@ class TestArg(unittest.TestCase): args = Arg(flags) args.add('x', 'foo', typ=bool) - self.assertTrue(args.match('foo')) - self.assertFalse(args.match('bar')) - self.assertFalse(args.match('baz')) + self.assertFalse(args.match('foo', 0)) + self.assertTrue(args.match('foo', flags.FOO)) + self.assertFalse(args.match('bar', flags.BAR)) + self.assertFalse(args.match('bar', flags.BAZ)) + self.assertFalse(args.match('baz', flags.BAR)) + self.assertFalse(args.match('baz', flags.BAZ)) args.add('y', 'bar', typ=bool) - self.assertTrue(args.match('foo')) - self.assertTrue(args.match('bar')) - self.assertTrue(args.match('baz')) + self.assertTrue(args.match('foo', flags.FOO)) + self.assertTrue(args.match('bar', flags.BAR)) + self.assertTrue(args.match('bar', flags.BAZ)) + self.assertFalse(args.match('baz', flags.BAR)) + self.assertTrue(args.match('baz', flags.BAZ)) if __name__ == '__main__':