소스 검색

fix get_ids and add testing for the method

oz123 11 년 전
부모
커밋
02270ee61c
2개의 변경된 파일14개의 추가작업 그리고 8개의 파일을 삭제
  1. 9 2
      pwman/tests/db_tests.py
  2. 5 6
      pwman/ui/cli.py

+ 9 - 2
pwman/tests/db_tests.py

@@ -1,7 +1,7 @@
 import os
 import os.path
 import sys
-from pwman.ui.tools import CLICallback, DummyCallback
+from pwman.ui.tools import DummyCallback
 
 if 'darwin' in sys.platform:
     from pwman.ui.mac import PwmanCliMac as PwmanCliOld
@@ -164,4 +164,11 @@ class CLITests(unittest.TestCase):
 
     def test_get_ids(self):
         #used by do_cp or do_open
-        pass
+        import ipdb; ipdb.set_trace()  # XXX BREAKPOINT
+
+        self.assertEqual([1], self.tester.cli.get_ids('1'))
+        self.assertListEqual([1, 2, 3, 4, 5], self.tester.cli.get_ids('1-5'))
+        self.assertListEqual([], self.tester.cli.get_ids('5-1'))
+        self.assertListEqual([], self.tester.cli.get_ids('5x-1'))
+        self.assertListEqual([], self.tester.cli.get_ids('5x'))
+        self.assertListEqual([], self.tester.cli.get_ids('5\\'))

+ 5 - 6
pwman/ui/cli.py

@@ -91,16 +91,15 @@ class PwmanCliOld(cmd.Cmd, HelpUI, BaseUI):
         rex = re.compile("^(?P<begin>\d+)(?:-(?P<end>\d+))?$")
         rex = rex.match(args)
         if hasattr(rex, 'groupdict'):
-            begin = int(rex.groupdict()['begin'])
-            end = int(rex.groupdict()['end'])
-
-            if end and begin:
-                # check that end is bigger than begin
+            try:
+                begin = int(rex.groupdict()['begin'])
+                end = int(rex.groupdict()['end'])
                 if not end > begin:
                     print("Start node should be smaller than end node")
                     return ids
                 ids += range(begin, end+1)
-            elif begin:
+                return ids
+            except TypeError:
                 ids.append(int(begin))
         else:
             print("Could not understand your input...")