def open(self) -> bool: if self._source == "?": self._error = "Use snapshot tab to see files available" return False try: # patch up correct filename fn = os.path.basename(self._source) full_path = pathlib.PurePath(SnapVariables.SNAPSHOT_DIRECTORY, fn) full_path = str(full_path) # now open the actual file file = FileMetaData.FileMetaData(full_path) ok, self._file, self._is_wav_file, data_type, sps, cf = file.open() self._has_meta_data = file.has_meta_data() # only update the following if we managed to recover them on the open() if ok: self.set_sample_type(data_type) # cf and sps can be overridden from ui self._centre_frequency_hz = cf self._sample_rate_sps = sps except ValueError as msg: self._error = msg logger.error(msg) raise ValueError(msg) self._connected = True return self._connected
def test_parse_filename_illegal_data_type(): ok, _, _, _, _ = FileMetaData.parse_filename("test.imag.1000.7f") assert not ok
def test_parse_filename_illegal_sample_rate(): ok, _, _, _, _ = FileMetaData.parse_filename("test.cplx.twoMhz.8t") assert not ok
def test_parse_filename_unsupported_real(): ok, _, _, _, _ = FileMetaData.parse_filename("test.real.1000.16tle") assert not ok
def test_parse_filename_illegal_real_complex_type(): ok, _, _, _, _ = FileMetaData.parse_filename("test.imag.1000.16tle") assert not ok
def test_parse_filename_ignore_too_many_cf_in_filename(): assert FileMetaData.parse_filename("test.cf.zero.cf1234.cplx.2000.16tbe") == (True, "16tbe", True, 2000.0, 0.0)
def test_parse_filename_not_enough_fields(): ok, _, _, _, _ = FileMetaData.parse_filename("test.cplx.1000") assert not ok
def test_parse_filename_centre_frequency_no_decimal_point(): assert FileMetaData.parse_filename("test.cf1234.cplx.2000.16tbe") == (True, "16tbe", True, 2000.0, 1234e6)
def test_parse_filename_centre_frequency(): assert FileMetaData.parse_filename("test.cf1234.1.cplx.2000.16tle") == (True, "16tle", True, 2000.0, 1234.1e6)
def test_parse_filename_with_bad_cf_number(): assert FileMetaData.parse_filename("test.cf433.a.cplx.1000.16tle") == (True, "16tle", True, 1000.0, 0.0)
def test_parse_filename_with_cf(): assert FileMetaData.parse_filename("test.cf433.5.cplx.1000.16tle") == (True, "16tle", True, 1000.0, 433500000.0)
def test_parse_filename(): assert FileMetaData.parse_filename("test.cplx.1000.16tle") == (True, "16tle", True, 1000.0, 0.0)