예제 #1
0
    def test_arguments(self, m_super):
        m_super.return_value = mock.Mock(
            arguments={
                '--id': Argument(),
                '--interface': Argument(),
                '--implementation': Argument()
            })

        bases = copy(dr.DeviceRemove.__bases__)
        f_bases = tuple(base for base in bases if base != ShowOne)

        m_base = mock.patch.object(dr.DeviceRemove, '__bases__', f_bases)
        with m_base:
            m_base.is_local = True
            t_device = dr.DeviceRemove()
            t_device.register_arguments(mock.Mock())

            m_super.assert_called_once()

            self.assertTrue('--id' in t_device._arguments.keys())
            self.assertFalse('--implementation' in t_device._arguments.keys())
            self.assertFalse('--interface' in t_device._arguments.keys())

        # ensure that is_local on the patch does not modify the actual bases
        self.assertEqual(bases, dr.DeviceRemove.__bases__)
예제 #2
0
 def arguments(self):
     if self._arguments is None:
         self._arguments = dict()
         self._arguments.update({
             'test': Argument('-t'),
             'impexp': Argument('-i')
         })
     return self._arguments
예제 #3
0
 def arguments(self):
     if self._arguments is None:
         self._arguments = dict()
         self._arguments.update({
             'name': Argument(
                 help="Unique name to help identify this device."),
             'implementation': Argument(
                 help="The specific implementation of radiation monitor "
                      "device see documentation for supported models."),
         })
     return self._arguments
예제 #4
0
 def arguments(self):
     if self._arguments is None:
         self._arguments = dict()
         self._arguments.update({
             '--device':
             Argument('-d',
                      type=int,
                      help="Device id for associated "
                      "measurements"),
             '--name':
             Argument('-n',
                      help="Device name for associated "
                      "measurements")
         })
     return self._arguments
예제 #5
0
 def arguments(self):
     if self._arguments is None:
         self._arguments = dict()
         self._arguments.update({
             '--id': Argument(
                 '-i', help="Database id associated with this object",
                 type=int),
             '--name': Argument(
                 '-n', help="Unique name to help identify this device."),
             '--interface': Argument(
                 '-f', help="Type of interface to communicate with the "
                            "radiation monitoring device."),
             '--implementation': Argument(
                 '-m', help="The specific implementation of radiation "
                            "monitor device. See documentation for "
                            "supported models."),
         })
     return self._arguments
예제 #6
0
 def arguments(self):
     if self._arguments is None:
         self._arguments = super().arguments
         self._arguments.update({
             '--detailed': Argument(
                 '-d', help="Show details related to the specific device "
                            "type if found.",
                 action="store_true")})
     return self._arguments
예제 #7
0
    def test_add_kwarg(self):
        arg = Argument()

        self.assertEqual(0, len(arg.kwargs()))

        arg.add_kwarg("test", "example")
        self.assertEqual({"test": "example"}, arg.kwargs())
예제 #8
0
 def arguments(self):
     if self._arguments is None:
         # retrieve existing arguments from baseclass
         self._arguments = super().arguments
         self._arguments.update({
             'port':
             Argument(
                 help="Symbolic name of the serial port to be translated "
                 "to the physical device, such as /dev/ttyUSB0 or "
                 "COM1."),
             'baudrate':
             Argument(
                 help="The speed at which the device sends data expressed "
                 "in symbols per second (baud), typically 9600 Bd/s."),
             '--bytesize':
             Argument('-b',
                      default=8,
                      type=int,
                      choices=BYTESIZE_CHOICES.values()),
             '--parity':
             Argument('-p', default="none",
                      choices=PARITY_CHOICES.values()),
             '---stopbits':
             Argument('-s',
                      default=1,
                      type=float,
                      choices=STOPBIT_CHOICES.values()),
             '--timeout':
             Argument('-t', default=None),
         })
     return self._arguments
예제 #9
0
 def arguments(self):
     if self._arguments is None:
         self._arguments = super().arguments
         self._arguments.update({
             '--port': Argument(
                 help="Symbolic name of the serial port to be translated "
                      "to the physical device, such as /dev/ttyUSB0 or "
                      "COM1.",
                 default=None),
             '--baudrate': Argument(
                 '-r', default=None,
                 help="The speed at which the device sends data expressed "
                      "in symbols per second (baud), typically 9600 Bd/s."
                 ),
             '--bytesize': Argument(
                 '-b', default=None, type=int,
                 choices=BYTESIZE_CHOICES.values()),
             '--parity': Argument(
                 '-p', default=None,
                 choices=PARITY_CHOICES.values()),
             '---stopbits': Argument(
                 '-s', default=None, type=float,
                 choices=STOPBIT_CHOICES.values()),
             '--timeout': Argument('-t', default=None),
         })
         if '--interface' in self._arguments:
             del self._arguments['--interface']
     return self._arguments
예제 #10
0
    def test_arguments(self, m_super):
        m_super.return_value = mock.Mock(arguments={
            '--device': Argument(),
            '--name': Argument()
        })

        bases = copy(mc.MeasurementList.__bases__)
        f_bases = tuple(base for base in bases if base != Lister)

        m_base = mock.patch.object(mc.MeasurementList, '__bases__', f_bases)
        with m_base:
            m_base.is_local = True
            t_device = mc.MeasurementList()
            t_device.register_arguments(mock.Mock())

            m_super.assert_called_once()

            self.assertTrue('--device' in t_device.arguments.keys())
            self.assertTrue('--name' in t_device.arguments.keys())

        # ensure that is_local on the patch does not modify the actual bases
        self.assertEqual(bases, mc.MeasurementList.__bases__)
예제 #11
0
    def test_add_kwarg_duplicate(self):
        arg = Argument()

        self.assertEqual(0, len(arg.kwargs()))

        self.assertTrue(arg.add_kwarg("test", "example"))
        self.assertFalse(arg.add_kwarg("test", "example2"))
        self.assertEqual({"test": "example"}, arg.kwargs())
예제 #12
0
    class TestHelper(ArgumentHelper):

        arguments = {
            'test': Argument(default="example"),
            '--test': Argument('-t', required=True),
        }
예제 #13
0
    def test_add_kwarg_none_str(self):
        arg = Argument()

        self.assertTrue(arg.add_kwarg(False, "example"))
        self.assertEqual({False: "example"}, arg.kwargs())
예제 #14
0
    def test_construct_kwargs(self):
        arg = Argument(default="test", required=True)

        self.assertEqual(2, len(arg.kwargs()))
        self.assertEqual({"default": "test", "required": True}, arg.kwargs())
예제 #15
0
    def test_construct_args(self):
        arg = Argument('-t')

        self.assertEqual(1, len(arg.args()))
        self.assertEqual(("-t", ), arg.args())