Example #1
0
def test_save_gqrx():
    tree = ttk.Treeview(columns=("frequency", "mode", "description",
                                 "lockout"),
                        displaycolumns=("frequency", "mode", "description"),
                        show="headings")
    bk = Bookmarks(tree, io=IO())
    bk.bookmarks.csv_save = MagicMock()
    bk.bookmarks.return_value = None
    bk._save_gqrx("test")
    assert (isinstance(bk.bookmarks.row_list, list))
    assert (len(bk.bookmarks.row_list) == 0)
Example #2
0
def test_import_rig_remote():
    tree = ttk.Treeview(columns=("frequency", "mode", "description",
                                 "lockout"),
                        displaycolumns=("frequency", "mode", "description"),
                        show="headings")
    value = [u'5,955,000', u'AM', u'found on 18.34 jan 08 2015', u'O']
    tree.insert("", 0, values=value)
    bk = Bookmarks(tree, io=IO())
    bk.load = MagicMock()
    bk.load.return_value = "test"
    bk._import_rig_remote("test")
    bk.load.assert_called_once_with("test", ",", silent=False)
Example #3
0
def bk():
    tree = ttk.Treeview(columns=("frequency", "mode", "description",
                                 "lockout"),
                        displaycolumns=("frequency", "mode", "description"),
                        show="headings")
    value = [u'5,955,000', u'AM', u'found on 18.34 jan 08 2015', u'O']
    bk_list = []
    bk_list.append(value)
    bk = Bookmarks(tree, io=IO())
    bk._insert_bookmarks(bk_list)

    return bk
Example #4
0
def test_save_gqrx_mode():
    tree = ttk.Treeview(columns=("frequency", "mode", "description",
                                 "lockout"),
                        displaycolumns=("frequency", "mode", "description"),
                        show="headings")
    value = [u'5,955,000', u'AM', u'found on 18.34 jan 08 2015', u'O']
    tree.insert("", 0, values=value)
    bk = Bookmarks(tree, io=IO())
    bk.bookmarks.csv_save = MagicMock()
    bk.bookmarks.return_value = None
    bk._save_gqrx("test")
    assert (bk.bookmarks.row_list[0][2] in CBB_MODES)
Example #5
0
    def __init__(self, config_file):
        """Default config, they will be overwritten when a conf is loaded
        this will be used to write a default config file.
        If the command line specifies a config file we note it in
        alternate_config_file and we use it, otherwise we check for
        the default one.

        :param alternate_config_file: config file passed as input argument
        :type alternate_config_file: string
        :raises: none
        :returns:none
        """

        self.io = IO()
        self.config_file = config_file
        self.config = dict.copy(DEFAULT_CONFIG)
Example #6
0
    def __init__(self, config_file):
        """Default config, they will be overwritten when a conf is loaded
        this will be used to write a default config file.
        If the command line specifies a config file we note it in
        alternate_config_file and we use it, otherwise we check for
        the default one.

        :param config_file: config file passed as input argument
        :type config_file: string
        :raises: none
        :returns:none
        """

        self.io = IO()
        self.config_file = config_file
        if not self.config_file:
            self.config = dict.copy(DEFAULT_CONFIG)
        else:
            self.config = {}
Example #7
0
def test_import_gqrx():
    tree = ttk.Treeview(columns=("frequency", "mode", "description",
                                 "lockout"),
                        displaycolumns=("frequency", "mode", "description"),
                        show="headings")
    value = [u'5,955,000', u'AM', u'found on 18.34 jan 08 2015', u'O']
    tree.insert("", 0, values=value)
    bk = Bookmarks(tree, io=IO())
    bk.bookmarks.csv_load = MagicMock()
    bk.bookmarks.csv_load.return_value = "test"
    bk.bookmarks.row_list.append([""])
    bk.bookmarks.row_list.append([""])
    bk.bookmarks.row_list.append([""])
    bk.bookmarks.row_list.append([""])
    bk.bookmarks.row_list.append([""])
    bk.bookmarks.row_list.append([
        "    28800000", " standing spike           ", " Narrow FM           ",
        "      10000", " Untagged"
    ])
    bk._insert_bookmarks = MagicMock()
    bk._import_gqrx("test")
    bk._insert_bookmarks.assert_called_once_with(
        [['28800000', 'FM', 'standing spike']])
Example #8
0
def test_bad_file2_csv_save():

    io = IO()
    io.row_list = [2, 2]
    with pytest.raises(csv.Error):
        io.csv_save("/tmp/test.csv", ",")
Example #9
0
def test_bad_file_csv_save():

    io = IO()
    with pytest.raises(TypeError):
        io.csv_save(["/tmp/test.csv", ","])
Example #10
0
class AppConfig(object):
    """This class reads the status of the UI and and parses the data
    so that it's suitable to be saved as a csv, and the reverse

    """

    def __init__(self, config_file):
        """Default config, they will be overwritten when a conf is loaded
        this will be used to write a default config file.
        If the command line specifies a config file we note it in
        alternate_config_file and we use it, otherwise we check for
        the default one.

        :param alternate_config_file: config file passed as input argument
        :type alternate_config_file: string
        :raises: none
        :returns:none
        """

        self.io = IO()
        self.config_file = config_file
        self.config = dict.copy(DEFAULT_CONFIG)

    def read_conf(self):
        """Read the configuration file.
        If the default one doesn't exist we create one with sane values.
        and then we re-read it. It logs an error if a line of the file is not
        valid and moves on to the next one.

        :param: none
        :raises: none
        :returns: none
        """
        if os.path.isfile(self.config_file):
            logger.info("Using config file:{}".format(self.config_file))
            self.io.csv_load(self.config_file, "=")
            error = 0
            for row in self.io.row_list:
                if len(row) == 2 and row[0].strip() in self.config.keys() :
                    self.config[row[0].strip()] = row[1].strip()
                else:
                    logger.warning("Error in config file line: " + str(row))
        else:
            self.write_conf()
            self.read_conf()

    def write_conf(self):
        """Writes the configuration to file. If the default config path
        is missing it will be created. If this is not possible the config file
        will not be saved.

        :param: none
        :raises: IOError, OSError if it is not possible to write the config
        :returns: none
        """

        self.io.row_list = []
        try:
            os.makedirs(os.path.dirname(self.config_file))
        except IOError:
            logger.info("Error while trying to create config "\
                              "path as {}".format(self.config_file))
        except OSError:
            logger.info("The config directory already exists.")
        for key in self.config.keys():
            row = []
            row.append(key)
            row.append(self.config[key])
            self.io.row_list.append(row)
        self.io.csv_save(self.config_file, "=")
Example #11
0
def test_detect_format():
    bk = Bookmarks("test", io=IO())
    with pytest.raises(InvalidPathError):
        bk._detect_format("")
Example #12
0
def test_non_existent_path():
    io=IO()
    with pytest.raises(InvalidPathError):
        io._path_check("")
Example #13
0
def test_bad_file2_csv_save():

    io=IO()
    io.row_list=[2,2]
    with pytest.raises(csv.Error):
        io.csv_save("/tmp/test.csv",",")
Example #14
0
def test_bad_file_csv_save():

    io=IO()
    io.row_list=2
    with pytest.raises(TypeError):
        io.csv_save("/tmp/test.csv",",")
Example #15
0
def test_good_path_csv_save():

    io=IO()
    io.csv_save("/tmp/test.csv",",")
Example #16
0
def test_good_path_csv_load():

    io=IO()
    io.csv_load("/tmp/",",")
Example #17
0
def test_export_panel():
    bk = Bookmarks("test", io=IO())
    tkFileDialog.asksaveasfilename = MagicMock()
    tkFileDialog.asksaveasfilename.return_Value = "testfile"
    bk._export_panel() == "testfile"
Example #18
0
def test_non_existent_path():
    io = IO()
    with pytest.raises(InvalidPathError):
        io._path_check("")
Example #19
0
def test_export_rig_remote_bad_attrib():
    bk = Bookmarks("test", io=IO())
    bk._export_panel = MagicMock()
    bk._export_panel.return_value == ""
    with pytest.raises(AttributeError):
        bk.export_rig_remote()
Example #20
0
def test_good_path_csv_load():

    io = IO()
    io.csv_load("/tmp/", ",")
Example #21
0
def test_good_path_csv_save():

    io = IO()
    io.csv_save("/tmp/test.csv", ",")
Example #22
0
 def __init__(self, tree, io=IO()):
     self.bookmarks = io
     self.tree = tree