Example #1
0
    def test_basic_incremental(self):
        inp = (u'index.markdown\n' '\tsection.markdown')
        sitemap = self.__parse_sitemap(inp)
        self.__create_md_file('index.markdown', (u'# My documentation\n'))
        self.__create_md_file('section.markdown', (u'# My section\n'))

        self.tree.parse_sitemap(sitemap)

        # Building from scratch, all pages are stale
        self.assertSetEqual(set(self.tree.get_stale_pages()),
                            set([u'index.markdown', u'section.markdown']))

        self.tree.persist()

        self.incremental = True
        self.tree = Tree(self, self)
        self.tree.parse_sitemap(sitemap)

        # Nothing changed, no page is stale
        self.assertSetEqual(set(self.tree.get_stale_pages()), set({}))

        # But we still have our pages
        self.assertSetEqual(set(self.tree.get_pages()),
                            set([u'index.markdown', u'section.markdown']))

        touch(os.path.join(self.__md_dir, u'section.markdown'))

        self.tree = Tree(self, self)
        self.tree.parse_sitemap(sitemap)

        self.assertSetEqual(set(self.tree.get_stale_pages()),
                            set([u'section.markdown']))
Example #2
0
    def _create_sitemap(self, name, contents):
        path = os.path.join(self._md_dir, name)
        with open(path, 'w') as _:
            _.write(contents)

        touch(path)
        return path
Example #3
0
    def _create_conf_file(self, name, conf):
        path = os.path.join(self._md_dir, name)
        with open(path, 'w') as _:
            _.write(json.dumps(conf, indent=4))

        touch(path)
        return path
Example #4
0
    def __create_md_file(self, name, contents):
        path = os.path.join(self.__md_dir, name)
        with open(path, 'w') as _:
            _.write(contents)

        # Just making sure we don't hit a race condition,
        # in real world situations it is assumed users
        # will not update source files twice in the same
        # microsecond
        touch(path)
Example #5
0
    def __create_md_file(self, name, contents):
        path = os.path.join(self.__md_dir, name)
        with open(path, 'w') as _:
            _.write(contents)

        # Just making sure we don't hit a race condition,
        # in real world situations it is assumed users
        # will not update source files twice in the same
        # microsecond
        touch(path)
Example #6
0
    def _create_md_file(self, name, contents):
        path = os.path.join(self._md_dir, name)
        try:
            os.mkdir(os.path.dirname(path))
        except FileExistsError:
            pass
        with open(path, 'w') as _:
            _.write(contents)

        touch(path)
        return path
Example #7
0
    def _create_src_file(self, name, symbols):
        path = os.path.join(self._src_dir, name)
        with open(path, 'w') as _:
            for symbol in symbols:
                _.write('%s\n' % symbol)

        # Just making sure we don't hit a race condition,
        # in real world situations it is assumed users
        # will not update source files twice in the same
        # microsecond
        touch(path)
        return path
Example #8
0
    def __create_src_file(self, name, symbols):
        path = os.path.join(self.__md_dir, name)
        with open(path, 'w') as _:
            for symbol in symbols:
                _.write('%s\n' % symbol)

        # Just making sure we don't hit a race condition,
        # in real world situations it is assumed users
        # will not update source files twice in the same
        # microsecond
        touch(path)

        return path
Example #9
0
    def test_dependencies(self):
        conf_file = os.path.join(self.__priv_dir, 'test.json')
        with open(conf_file, 'w') as _:
            _.write(
                '{\n'
                '"index": "my_index.markdown",\n'
                '"test_index": "/home/meh/test_index.markdown",\n'
                '"test_sources": ["*.x"],\n'
                '"test_source_filters": ["foobar.x"]\n'
                '}\n')

        touch(os.path.join(self.__priv_dir, 'foo.x'))
        touch(os.path.join(self.__priv_dir, 'bar.x'))
        touch(os.path.join(self.__priv_dir, 'baz.x'))
        touch(os.path.join(self.__priv_dir, 'foobar.x'))

        cp = ConfigParser(conf_file=conf_file)

        deps = set([os.path.abspath(dep) for dep in cp.get_dependencies()])

        self.assertSetEqual(
            deps,
            set([os.path.join(self.__priv_dir, 'foo.x'),
                 os.path.join(self.__priv_dir, 'bar.x'),
                 os.path.join(self.__priv_dir, 'baz.x'),
                 conf_file]))
Example #10
0
    def test_dependencies(self):
        conf_file = os.path.join(self.__priv_dir, 'test.json')
        with open(conf_file, 'w') as _:
            _.write('{\n'
                    '"index": "my_index.markdown",\n'
                    '"test_index": "/home/meh/test_index.markdown",\n'
                    '"test_sources": ["*.x"],\n'
                    '"test_source_filters": ["foobar.x"]\n'
                    '}\n')

        touch(os.path.join(self.__priv_dir, 'foo.x'))
        touch(os.path.join(self.__priv_dir, 'bar.x'))
        touch(os.path.join(self.__priv_dir, 'baz.x'))
        touch(os.path.join(self.__priv_dir, 'foobar.x'))

        cfg = Config(conf_file=conf_file)

        deps = set([os.path.abspath(dep) for dep in cfg.get_dependencies()])

        self.assertSetEqual(
            deps,
            set([
                os.path.join(self.__priv_dir, 'foo.x'),
                os.path.join(self.__priv_dir, 'bar.x'),
                os.path.join(self.__priv_dir, 'baz.x'), conf_file
            ]))
Example #11
0
    def test_cli_overrides(self):
        conf_file = os.path.join(self.__priv_dir, 'test.json')
        with open(conf_file, 'w') as _:
            _.write('{\n'
                    '"index": "my_index.markdown",\n'
                    '"test_index": "/home/meh/test_index.markdown",\n'
                    '"test_sources": ["*.x"],\n'
                    '"test_source_filters": ["foobar.x"]\n'
                    '}\n')

        touch(os.path.join(self.__priv_dir, 'foo.x'))
        touch(os.path.join(self.__priv_dir, 'foobar.x'))

        here = os.path.abspath(os.path.dirname(__file__))
        invoke_dir = os.getcwd()
        relpath = os.path.relpath(here, invoke_dir)
        overriden_src_dir = os.path.join(relpath, 'overridden_sources')

        shutil.rmtree(overriden_src_dir, ignore_errors=True)
        os.mkdir(overriden_src_dir)
        touch(os.path.join(overriden_src_dir, 'other.x'))
        touch(os.path.join(overriden_src_dir, 'foobar.x'))
        touch(os.path.join(overriden_src_dir, 'ignored.x'))

        cli = {
            'index': 'another_index.markdown',
            'test_sources': ['%s/*.x' % overriden_src_dir],
            'test_source_filters': ['%s/ignored.x' % overriden_src_dir]
        }

        cfg = Config(command_line_args=cli, conf_file=conf_file)
        self.assertEqual(cfg.get('index'), 'another_index.markdown')

        self.assertEqual(cfg.get_index(),
                         os.path.join(invoke_dir, 'another_index.markdown'))

        overriden_abs_dir = os.path.join(invoke_dir, overriden_src_dir)

        self.assertSetEqual(
            set(cfg.get_sources('test')),
            set([
                os.path.join(overriden_abs_dir, 'other.x'),
                os.path.join(overriden_abs_dir, 'foobar.x')
            ]))

        shutil.rmtree(overriden_src_dir, ignore_errors=True)
Example #12
0
    def test_basic_incremental(self):
        inp = (u'index.markdown\n'
               '\tsection.markdown')
        sitemap = self.__parse_sitemap(inp)
        self.__create_md_file(
            'index.markdown',
            (u'# My documentation\n'))
        self.__create_md_file(
            'section.markdown',
            (u'# My section\n'))

        doc_tree = DocTree(self.__priv_dir, self.include_paths)
        doc_tree.parse_sitemap(self.change_tracker, sitemap)

        # Building from scratch, all pages are stale
        self.assertSetEqual(
            set(doc_tree.get_stale_pages()),
            set([u'index.markdown',
                 u'section.markdown']))

        doc_tree.persist()

        doc_tree = DocTree(self.__priv_dir, self.include_paths)
        doc_tree.parse_sitemap(self.change_tracker, sitemap)

        # Nothing changed, no page is stale
        self.assertSetEqual(
            set(doc_tree.get_stale_pages()),
            set({}))

        # But we still have our pages
        self.assertSetEqual(
            set(doc_tree.get_pages()),
            set([u'index.markdown',
                 u'section.markdown']))

        touch(os.path.join(self.__md_dir, u'section.markdown'))

        doc_tree = DocTree(self.__priv_dir, self.include_paths)
        doc_tree.parse_sitemap(self.change_tracker, sitemap)

        self.assertSetEqual(
            set(doc_tree.get_stale_pages()),
            set([u'section.markdown']))
Example #13
0
    def test_cli_overrides(self):
        conf_file = os.path.join(self.__priv_dir, 'test.json')
        with open(conf_file, 'w') as _:
            _.write(
                '{\n'
                '"index": "my_index.markdown",\n'
                '"test_index": "/home/meh/test_index.markdown",\n'
                '"test_sources": ["*.x"],\n'
                '"test_source_filters": ["foobar.x"]\n'
                '}\n')

        touch(os.path.join(self.__priv_dir, 'foo.x'))
        touch(os.path.join(self.__priv_dir, 'foobar.x'))

        here = os.path.abspath(os.path.dirname(__file__))
        invoke_dir = os.getcwd()
        relpath = os.path.relpath(here, invoke_dir)
        overriden_src_dir = os.path.join(relpath, 'overridden_sources')

        shutil.rmtree(overriden_src_dir, ignore_errors=True)
        os.mkdir(overriden_src_dir)
        touch(os.path.join(overriden_src_dir, 'other.x'))
        touch(os.path.join(overriden_src_dir, 'foobar.x'))
        touch(os.path.join(overriden_src_dir, 'ignored.x'))

        cli = {'index': 'another_index.markdown',
               'test_sources': ['%s/*.x' % overriden_src_dir],
               'test_source_filters': ['%s/ignored.x' % overriden_src_dir]}

        cp = ConfigParser(command_line_args=cli, conf_file=conf_file)
        self.assertEqual(cp.get('index'), 'another_index.markdown')

        self.assertEqual(cp.get_index(),
                         os.path.join(invoke_dir, 'another_index.markdown'))

        overriden_abs_dir = os.path.join(invoke_dir, overriden_src_dir)

        self.assertSetEqual(
            set(cp.get_sources('test_')),
            set([os.path.join(overriden_abs_dir, 'other.x'),
                 os.path.join(overriden_abs_dir, 'foobar.x')]))

        shutil.rmtree(overriden_src_dir, ignore_errors=True)
Example #14
0
    def test_sources(self):
        conf_file = os.path.join(self.__priv_dir, 'test.json')
        with open(conf_file, 'w') as _:
            _.write(
                '{\n'
                '"test_sources": ["*.x"],\n'
                '"test_source_filters": ["foobar.x"]\n'
                '}\n')

        touch(os.path.join(self.__priv_dir, 'foo.x'))
        touch(os.path.join(self.__priv_dir, 'bar.x'))
        touch(os.path.join(self.__priv_dir, 'baz.x'))
        touch(os.path.join(self.__priv_dir, 'foobar.x'))

        cp = ConfigParser(conf_file=conf_file)
        self.assertSetEqual(
            set(cp.get_sources('test_')),
            set([os.path.join(self.__priv_dir, 'foo.x'),
                 os.path.join(self.__priv_dir, 'bar.x'),
                 os.path.join(self.__priv_dir, 'baz.x')]))
Example #15
0
    def test_sources(self):
        conf_file = os.path.join(self.__priv_dir, 'test.json')
        with open(conf_file, 'w') as _:
            _.write('{\n'
                    '"test_sources": ["*.x"],\n'
                    '"test_source_filters": ["foobar.x"]\n'
                    '}\n')

        touch(os.path.join(self.__priv_dir, 'foo.x'))
        touch(os.path.join(self.__priv_dir, 'bar.x'))
        touch(os.path.join(self.__priv_dir, 'baz.x'))
        touch(os.path.join(self.__priv_dir, 'foobar.x'))

        cfg = Config(conf_file=conf_file)
        self.assertSetEqual(
            set(cfg.get_sources('test')),
            set([
                os.path.join(self.__priv_dir, 'foo.x'),
                os.path.join(self.__priv_dir, 'bar.x'),
                os.path.join(self.__priv_dir, 'baz.x')
            ]))
Example #16
0
 def __touch_src_file(self, name):
     path = os.path.join(self.__md_dir, name)
     touch(path)
Example #17
0
 def __touch_src_file(self, name):
     path = os.path.join(self.__md_dir, name)
     touch(path)