def find_listfiles(self, filetype, pcc=None): files = [] if not pcc: pcc = self.pcc (entries, source) = read_lst_file(pcc) for line in entries: elements = line.split(":", 1) type = elements[0] data = elements[1].rstrip() # PRE attributes on the .lst file if data.find("|") >= 0: elements = data.split("|", 1) data = elements[0] if type == filetype: files.append((pcc.parent.child(data), source)) if type == "PCC": # relative paths start with @/ if data.startswith("@/"): pccpath = Path(settings.DATADIR, data[2:]) else: pccpath = Path(pcc.parent, data) pccfiles = self.find_listfiles(filetype, pccpath) files = files + pccfiles return files
def test_read_lst_file_returns_source_definition(self): (ret, source) = read_lst_file("core/testnaam.lst") self.assertEqual(source["sourcefile"], "core/testnaam.lst") self.assertEqual(source["sourcelong"], "Core Rulebook")
def test_read_lst_file_filters_empty_lines(self): (ret, source) = read_lst_file("Testnaam") for line in ret: self.assertTrue(len(line) > 0, "line has zero length")
def test_read_lst_file_filters_lines_starting_with_whitespace(self): (ret, source) = read_lst_file("Testnaam") for line in ret: self.assertFalse(re.search(r'^\s', line), "line starts with white-space: '%s'" % line)
def test_read_lst_file_filters_lines_starting_with_hash(self): (ret, source) = read_lst_file("Testnaam") for line in ret: self.assertFalse(line.startswith("#"), "line starts with hash: %s" % line)
def test_read_lst_file_filters_source_lines(self): (ret, source) = read_lst_file("Testnaam") for line in ret: self.assertFalse(line.startswith("SOURCELONG:"), "line starts with source token: '%s'" % line)
def test_read_lst_file_filters_copy(self): (ret, source) = read_lst_file("Testnaam") for line in ret: self.assertFalse(re.search(r'^[^\t]*\.COPY', line), "line is a COPY line: %s" % line)
def test_read_lst_file_filters_mods(self): (ret, source) = read_lst_file("Testnaam") for line in ret: self.assertFalse(re.search(r'^[^\t]*\.MOD', line), "line is a MOD line: %s" % line)
def test_read_lst_file_returns_a_list_of_lines_in_file(self): (ret, source) = read_lst_file("Testnaam") ret[0]
def test_read_lst_file_opens_designated_file(self): read_lst_file("testnaam") self.mock_open.assert_called_once_with("testnaam")
def setUp(self): self.test_spells = Path(settings.DATADIR, "pathfinder/paizo/roleplaying_game/core_rulebook/cr_spells.lst") (self.test_lines, self.source) = read_lst_file(self.test_spells)