Пример #1
0
def mkcache(file):
    return datastructures.FileCache(
        [
            (".", [os.path.dirname(file)], []),
            (os.path.dirname(file), [], [os.path.basename(file)]),
        ]
    )
 def test_that_all_files_are_contained(self):
     files = [('anh03', 0, ('anh0301.md', 'anh0302.md')),
             ('k20', 0, ('k20.md',)),
             ('anh04', 0, ('anh04.md',))]
     f = datastructures.FileCache(files)
     for file in [e[2] for e in files]:
         file = (file[0] if not isinstance(file, str) else file)
         self.assertTrue(file in f, "%s should be contained in the cache" % file)
 def test_that_files_are_grouped_correctly(self):
     appendix =  ('anh03', 0, ('anh0301.md', 'anh0302.md'))
     preface = ('v04', 0, ('v04.md',))
     main = ('blatt05', 0, ('blatt05.md',))
     f = datastructures.FileCache((preface, main, appendix))
     self.assertEqual(f._FileCache__preface[0][1], preface[2][0],
             "%s should be contained in the preface group" % preface[2][0])
     self.assertEqual(appendix[2][0], f._FileCache__appendix[0][1],
             "%s should be contained in the appendix group" % appendix[2][0])
     self.assertEqual(main[2][0], f._FileCache__main[0][1],
             "%s should be contained in the main group" % main[2][0])
 def test_that_get_neighbours_returns_correct_neighbours_or_none(self):
     files = [('anh03', 0, ('anh0301.md', 'anh0302.md')),
             ('v04', 0, ('v04.md',)), ('blatt05', 0, ('blatt05.md',))]
     f = datastructures.FileCache(files)
     # this one has two neighbours
     # ToDo: "in" must be used
     self.assertEqual(f.get_neighbours_for('blatt05/blatt05.md'),
             (('v04', 'v04.md'), ('anh03', 'anh0301.md')))
     # this one has only a next
     self.assertEqual(f.get_neighbours_for('v04/v04.md'),
             (None, ('blatt05','blatt05.md')))
     # this one has only a previous
     self.assertEqual(f.get_neighbours_for('anh03/anh0302.md'),
             (('anh03', 'anh0301.md'), None))
Пример #5
0
    def setUp(self):
        self.files = (('.', ('anh01', 'v01', 'k01',), ('index.html',)),
                ('anh01', [], ('anh01.md',)),
                ('k01', (), ('k01.md',)),
                ('v01', (), ('v01.md',))
                )
        self.cache = datastructures.FileCache(self.files)
        self.pagenumbers = []
        for i in range(1,50):
            self.pagenumbers.append(datastructures.PageNumber('Seite', i))

        # set up test directory
        self.original_directory = os.getcwd()
        self.tmpdir = tempfile.mkdtemp()
        os.chdir(self.tmpdir)
        for d, _, files in self.files:
            if not os.path.exists(d):
                os.mkdir(d)
            for f in files:
                with open(os.path.join(d, f), 'w') as file:
                    file.write('\n')
Пример #6
0
    def setUp(self):
        self.files = (
            (".", ("anh01", "v01", "k01"), ("index.html",)),
            ("anh01", [], ("anh01.md",)),
            ("k01", (), ("k01.md",)),
            ("v01", (), ("v01.md",)),
        )
        self.cache = datastructures.FileCache(self.files)
        self.pagenumbers = []
        for i in range(1, 50):
            self.pagenumbers.append(datastructures.PageNumber("Seite", i))

        # set up test directory
        self.original_directory = os.getcwd()
        self.tmpdir = tempfile.mkdtemp()
        os.chdir(self.tmpdir)
        for d, _, files in self.files:
            if not os.path.exists(d):
                os.mkdir(d)
            for f in files:
                with open(os.path.join(d, f), "w") as file:
                    file.write("\n")
 def test_that_invalid_file_names_raise_exception(self):
     with self.assertRaises(errors.StructuralError):
         datastructures.FileCache([('foo', 0, ('foobar.md',))])
 def test_requesting_neighbours_for_not_existing_files_raises_exception(self):
     f = datastructures.FileCache([('anh03', 0, ('anh0301.md',))])
     with self.assertRaises(errors.StructuralError):
         #pylint: disable=pointless-statement
         f.get_neighbours_for("fooo.md")