summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorian Ludwig <f.ludwig@greyrook.com>2020-08-31 20:11:08 +0200
committerFlorian Ludwig <f.ludwig@greyrook.com>2020-08-31 20:11:08 +0200
commitaa7e197af90fc889561396eee9b6809e99c1331a (patch)
tree803946184dcb4aba9ce7a4baf4d30f38c448d52e
parent652d2e60eff064bfa803474919c88c0e84134cef (diff)
downloadrdflib-aa7e197af90fc889561396eee9b6809e99c1331a.tar.gz
remove import side-effects
-rw-r--r--rdflib/__init__.py33
-rw-r--r--test/test_parse_file_guess_format.py7
2 files changed, 5 insertions, 35 deletions
diff --git a/rdflib/__init__.py b/rdflib/__init__.py
index 06b1c2eb..b6949f5f 100644
--- a/rdflib/__init__.py
+++ b/rdflib/__init__.py
@@ -83,39 +83,6 @@ __all__ = [
"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
"""
diff --git a/test/test_parse_file_guess_format.py b/test/test_parse_file_guess_format.py
index 5706f8df..b4085376 100644
--- a/test/test_parse_file_guess_format.py
+++ b/test/test_parse_file_guess_format.py
@@ -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):
@@ -19,10 +20,12 @@ class FileParserGuessFormatTest(unittest.TestCase):
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))