-
Notifications
You must be signed in to change notification settings - Fork 456
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Let nikola serve work together with non-root BASE_URL or SITE_URL. Fixes
#3726 (#3804) * Let nikola serve work together with non-root BASE_URL or SITE_URL. * Backporting a type hint to Python 3.8. * pydocstyle improvement. * Comment cosmetics. * Workaround for Windows \r\n newlines. * Moving the base-path extraction to utils.py. * Fixing imports that were wrongly done by my dev ide.
- Loading branch information
1 parent
1da7205
commit 731ee4b
Showing
8 changed files
with
279 additions
and
103 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import pathlib | ||
import socket | ||
from typing import Dict, Any | ||
|
||
from ..helper import FakeSite | ||
from nikola.utils import get_logger | ||
|
||
SERVER_ADDRESS = "localhost" | ||
TEST_MAX_DURATION = 10 # Watchdog: Give up the test if it did not succeed during this time span. | ||
|
||
# Folder that has the fixture file we expect the server to serve: | ||
OUTPUT_FOLDER = pathlib.Path(__file__).parent.parent / "data" / "dev_server_sample_output_folder" | ||
|
||
LOGGER = get_logger("test_dev_server") | ||
|
||
|
||
def find_unused_port() -> int: | ||
"""Ask the OS for a currently unused port number. | ||
(More precisely, a port that can be used for a TCP server servicing SERVER_ADDRESS.) | ||
We use a method here rather than a fixture to minimize side effects of failing tests. | ||
""" | ||
s = socket.socket() | ||
try: | ||
ANY_PORT = 0 | ||
s.bind((SERVER_ADDRESS, ANY_PORT)) | ||
address, port = s.getsockname() | ||
LOGGER.info("Trying to set up dev server on http://%s:%i/", address, port) | ||
return port | ||
finally: | ||
s.close() | ||
|
||
|
||
class MyFakeSite(FakeSite): | ||
def __init__(self, config: Dict[str, Any], configuration_filename="conf.py"): | ||
super(MyFakeSite, self).__init__() | ||
self.configured = True | ||
self.debug = True | ||
self.THEMES = [] | ||
self._plugin_places = [] | ||
self.registered_auto_watched_folders = set() | ||
self.config = config | ||
self.configuration_filename = configuration_filename |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.