示例#1
0
    def test_model(self):
        scanner = VirtualScanner()
        model = scanner.get_model()
        self.assertEqual(model, "VIRTUAL")

        with self.assertRaises(ScannerException):
            scanner = NonRespondingScanner()
            model = scanner.get_model()

        with self.assertRaises(ScannerException):
            scanner = ErrorRespondingScanner()
            model = scanner.get_model()

        with self.assertRaises(ScannerException):
            scanner = GarbageRespondingScanner()
            model = scanner.get_model()
示例#2
0
    def test_channel_get(self):
        scanner = VirtualScanner()
        channel = scanner.get_channel(1)
        self.assertEqual(channel.name, "Channel 1")
        self.assertEqual(channel.freqcode, "01010000")
        self.assertEqual(channel.modulation, "FM")
        self.assertEqual(channel.delay, 2)

        with self.assertRaises(ScannerException):
            scanner = NonRespondingScanner()
            channel = scanner.get_channel(1)

        with self.assertRaises(ScannerException):
            scanner = ErrorRespondingScanner()
            channel = scanner.get_channel(1)

        with self.assertRaises(ScannerException):
            scanner = GarbageRespondingScanner()
            channel = scanner.get_channel(1)
示例#3
0
    def test_model(self):
        scanner = VirtualScanner()
        model = scanner.get_model()
        self.assertEqual(model, "VIRTUAL")

        with self.assertRaises(ScannerException):
            scanner = NonRespondingScanner()
            model = scanner.get_model()

        with self.assertRaises(ScannerException):
            scanner = ErrorRespondingScanner()
            model = scanner.get_model()

        with self.assertRaises(ScannerException):
            scanner = GarbageRespondingScanner()
            model = scanner.get_model()
示例#4
0
    def test_channel_get(self):
        scanner = VirtualScanner()
        channel = scanner.get_channel(1)
        self.assertEqual(channel.name, "Channel 1")
        self.assertEqual(channel.freqcode, "01010000")
        self.assertEqual(channel.modulation, "FM")
        self.assertEqual(channel.delay, 2)

        with self.assertRaises(ScannerException):
            scanner = NonRespondingScanner()
            channel = scanner.get_channel(1)

        with self.assertRaises(ScannerException):
            scanner = ErrorRespondingScanner()
            channel = scanner.get_channel(1)

        with self.assertRaises(ScannerException):
            scanner = GarbageRespondingScanner()
            channel = scanner.get_channel(1)
示例#5
0
    def get_scanner(self):
        # Virtual scanner requested
        if self.params.noscanner:
            self.print_verbose("Using virtual scanner device.")
            return VirtualScanner()

        else:  # pragma: no cover
            # Look for a compatible device
            self.print_verbose("Searching for compatible devices...")

            lookup = DeviceLookup()
            device = lookup.get_device()

            if not device:
                sys.exit("No compatible scanner was found.")

            if not lookup.is_tty(device):
                sys.exit(
                    "Found a compatible scanner, but no serial tty.\n"
                    "Please run the following commands with root privileges:\n"
                    "modprobe usbserial vendor=0x{0} product=0x{1}".format(
                        device.get("ID_VENDOR_ID"), device.get("ID_MODEL_ID")))

            # Make sure device is writable by current user
            if not os.access(device.get("DEVNAME", ""), os.W_OK):
                sys.exit(
                    "Found a compatible scanner, but can not write to it.")

            scanner = Scanner(device.get("DEVNAME"), self.params.rate)

            try:
                model = scanner.get_model()
            except ScannerException:
                sys.exit("Could not get model name from scanner.\n"
                         "Please try again or reconnect your device.")

            self.print_verbose("Found scanner", model)

            return scanner
示例#6
0
    def test_exit_programming(self):
        scanner = VirtualScanner()
        scanner.exit_programming()

        with self.assertRaises(ScannerException):
            scanner = NonRespondingScanner()
            scanner.exit_programming()

        with self.assertRaises(ScannerException):
            scanner = ErrorRespondingScanner()
            scanner.exit_programming()

        with self.assertRaises(ScannerException):
            scanner = GarbageRespondingScanner()
            scanner.exit_programming()
示例#7
0
    def test_channel_delete(self):
        scanner = VirtualScanner()
        scanner.delete_channel(1)

        class NonRespondingDelete(EnsureChannelDelete, NonRespondingScanner):
            pass

        with self.assertRaises(ScannerException):
            scanner = NonRespondingDelete()
            scanner.delete_channel(1)

        class ErrorRespondingDelete(EnsureChannelDelete, NonRespondingScanner):
            pass

        with self.assertRaises(ScannerException):
            scanner = ErrorRespondingDelete()
            scanner.delete_channel(1)

        class GarbageRespondingDelete(EnsureChannelDelete, NonRespondingScanner):
            pass

        with self.assertRaises(ScannerException):
            scanner = GarbageRespondingDelete()
            scanner.delete_channel(1)
示例#8
0
    def test_channel_set(self):
        ch = Channel(**{
            "index": 1,
            "name": "Channel name",
            "frequency": "100.1234",
            "modulation": "FM",
            "tqcode": 0,
            "delay": 2,
            "lockout": False,
            "priority": False,
        })

        scanner = VirtualScanner()
        scanner.set_channel(ch)

        with self.assertRaises(ScannerException):
            scanner = NonRespondingScanner()
            scanner.set_channel(ch)

        with self.assertRaises(ScannerException):
            scanner = ErrorRespondingScanner()
            scanner.set_channel(ch)

        with self.assertRaises(ScannerException):
            scanner = GarbageRespondingScanner()
            scanner.set_channel(ch)
示例#9
0
    def test_exit_programming(self):
        scanner = VirtualScanner()
        scanner.exit_programming()

        with self.assertRaises(ScannerException):
            scanner = NonRespondingScanner()
            scanner.exit_programming()

        with self.assertRaises(ScannerException):
            scanner = ErrorRespondingScanner()
            scanner.exit_programming()

        with self.assertRaises(ScannerException):
            scanner = GarbageRespondingScanner()
            scanner.exit_programming()
示例#10
0
    def test_channel_delete(self):
        scanner = VirtualScanner()
        scanner.delete_channel(1)

        class NonRespondingDelete(EnsureChannelDelete, NonRespondingScanner):
            pass

        with self.assertRaises(ScannerException):
            scanner = NonRespondingDelete()
            scanner.delete_channel(1)

        class ErrorRespondingDelete(EnsureChannelDelete, NonRespondingScanner):
            pass

        with self.assertRaises(ScannerException):
            scanner = ErrorRespondingDelete()
            scanner.delete_channel(1)

        class GarbageRespondingDelete(EnsureChannelDelete,
                                      NonRespondingScanner):
            pass

        with self.assertRaises(ScannerException):
            scanner = GarbageRespondingDelete()
            scanner.delete_channel(1)
示例#11
0
    def test_channel_set(self):
        ch = Channel(
            **{
                "index": 1,
                "name": "Channel name",
                "frequency": "100.1234",
                "modulation": "FM",
                "tqcode": 0,
                "delay": 2,
                "lockout": False,
                "priority": False,
            })

        scanner = VirtualScanner()
        scanner.set_channel(ch)

        with self.assertRaises(ScannerException):
            scanner = NonRespondingScanner()
            scanner.set_channel(ch)

        with self.assertRaises(ScannerException):
            scanner = ErrorRespondingScanner()
            scanner.set_channel(ch)

        with self.assertRaises(ScannerException):
            scanner = GarbageRespondingScanner()
            scanner.set_channel(ch)