Пример #1
0
 def test_files(self):
     fs = [
         File('index.md',
              '/path/to/docs',
              '/path/to/site',
              use_directory_urls=True),
         File('foo/bar.md',
              '/path/to/docs',
              '/path/to/site',
              use_directory_urls=True),
         File('foo/bar.html',
              '/path/to/docs',
              '/path/to/site',
              use_directory_urls=True),
         File('foo/bar.jpg',
              '/path/to/docs',
              '/path/to/site',
              use_directory_urls=True),
         File('foo/bar.js',
              '/path/to/docs',
              '/path/to/site',
              use_directory_urls=True),
         File('foo/bar.css',
              '/path/to/docs',
              '/path/to/site',
              use_directory_urls=True)
     ]
     files = Files(fs)
     self.assertEqual([f for f in files], fs)
     self.assertEqual(len(files), 6)
     self.assertEqual(files.documentation_pages(), [fs[0], fs[1]])
     self.assertEqual(files.static_pages(), [fs[2]])
     self.assertEqual(files.media_files(), [fs[3], fs[4], fs[5]])
     self.assertEqual(files.javascript_files(), [fs[4]])
     self.assertEqual(files.css_files(), [fs[5]])
     self.assertEqual(files.get_file_from_path('foo/bar.jpg'), fs[3])
     self.assertEqual(files.get_file_from_path('foo/bar.jpg'), fs[3])
     self.assertEqual(files.get_file_from_path('missing.jpg'), None)
     self.assertTrue(fs[2].src_path in files)
     self.assertTrue(fs[2].src_path in files)
     extra_file = File('extra.md',
                       '/path/to/docs',
                       '/path/to/site',
                       use_directory_urls=True)
     self.assertFalse(extra_file.src_path in files)
     files.append(extra_file)
     self.assertEqual(len(files), 7)
     self.assertTrue(extra_file.src_path in files)
     self.assertEqual(files.documentation_pages(),
                      [fs[0], fs[1], extra_file])
Пример #2
0
 def test_build_page(self, site_dir):
     cfg = load_config(site_dir=site_dir, nav=['index.md'], plugins=[])
     files = Files([
         File('index.md', cfg['docs_dir'], cfg['site_dir'],
              cfg['use_directory_urls'])
     ])
     nav = get_navigation(files, cfg)
     page = files.documentation_pages()[0].page
     # Fake populate page
     page.title = 'Title'
     page.markdown = 'page content'
     page.content = '<p>page content</p>'
     build._build_page(page, cfg, files, nav, cfg['theme'].get_env())
     self.assertPathIsFile(site_dir, 'index.html')
Пример #3
0
 def test_build_page_plugin_error(self, site_dir, mock_write_file):
     cfg = load_config(site_dir=site_dir, nav=['index.md'], plugins=[])
     files = Files([
         File('index.md', cfg['docs_dir'], cfg['site_dir'],
              cfg['use_directory_urls'])
     ])
     nav = get_navigation(files, cfg)
     page = files.documentation_pages()[0].page
     # Fake populate page
     page.title = 'Title'
     page.markdown = 'page content'
     page.content = '<p>page content</p>'
     with self.assertLogs('mkdocs', level='ERROR') as cm:
         self.assertRaises(PluginError, build._build_page, page, cfg, files,
                           nav, cfg['theme'].get_env())
     self.assertEqual(
         cm.output,
         ["ERROR:mkdocs.commands.build:Error building page 'index.md':"])
     self.assert_mock_called_once(mock_write_file)
Пример #4
0
 def test_build_page_dirty_not_modified(self, site_dir, mock_write_file):
     cfg = load_config(site_dir=site_dir, nav=['testing.md'], plugins=[])
     files = Files([
         File('testing.md', cfg['docs_dir'], cfg['site_dir'],
              cfg['use_directory_urls'])
     ])
     nav = get_navigation(files, cfg)
     page = files.documentation_pages()[0].page
     # Fake populate page
     page.title = 'Title'
     page.markdown = 'page content'
     page.content = '<p>page content</p>'
     build._build_page(page,
                       cfg,
                       files,
                       nav,
                       cfg['theme'].get_env(),
                       dirty=True)
     self.assert_mock_called_once(mock_write_file)