summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAshley Sommer <ashleysommer@gmail.com>2020-09-17 14:34:50 +1000
committerGitHub <noreply@github.com>2020-09-17 14:34:50 +1000
commit81c4dbb40a8c8815a0219645db06efccac74f01d (patch)
treee3c7afb4a91d2efa2591d643bce5bb2d6ce3ada9
parentb3bb4db6c7d0bfd7812597588f8c7e3fe2e34800 (diff)
parentaa7e197af90fc889561396eee9b6809e99c1331a (diff)
downloadrdflib-81c4dbb40a8c8815a0219645db06efccac74f01d.tar.gz
Merge pull request #1156 from FlorianLudwig/cleanup_init
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))