Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove import side-effects #1156

Merged
merged 1 commit into from
Sep 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
33 changes: 0 additions & 33 deletions rdflib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,39 +83,6 @@
"util",
]

import sys

import logging

logger = logging.getLogger(__name__)
_interactive_mode = False
try:
import __main__

if (
not hasattr(__main__, "__file__")
and sys.stdout is not None
and sys.stderr.isatty()
):
# show log messages in interactive mode
_interactive_mode = True
logger.setLevel(logging.INFO)
logger.addHandler(logging.StreamHandler())
del __main__
except ImportError:
# Main already imported from elsewhere
import warnings

warnings.warn("__main__ already imported", ImportWarning)
del warnings

if _interactive_mode:
logger.info("RDFLib Version: %s" % __version__)
else:
logger.debug("RDFLib Version: %s" % __version__)
del _interactive_mode
del sys


NORMALIZE_LITERALS = True
"""
Expand Down
7 changes: 5 additions & 2 deletions test/test_parse_file_guess_format.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import unittest
import logging
from pathlib import Path
from shutil import copyfile
from tempfile import TemporaryDirectory

from rdflib.exceptions import ParserError

from rdflib import Graph, logger as graph_logger
from rdflib import Graph


class FileParserGuessFormatTest(unittest.TestCase):
Expand All @@ -19,10 +20,12 @@ def test_n3(self):

def test_warning(self):
g = Graph()
graph_logger = logging.getLogger("rdflib")

with TemporaryDirectory() as tmpdirname:
newpath = Path(tmpdirname).joinpath("no_file_ext")
copyfile("test/rdf/Manifest.rdf", str(newpath))
with self.assertLogs(graph_logger, "WARNING") as log_cm:
with self.assertLogs(graph_logger, "WARNING"):
with self.assertRaises(ParserError):
g.parse(str(newpath))

Expand Down