Skip to content

Commit

Permalink
remove import side-effects
Browse files Browse the repository at this point in the history
  • Loading branch information
FlorianLudwig committed Aug 31, 2020
1 parent 652d2e6 commit aa7e197
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 35 deletions.
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

0 comments on commit aa7e197

Please sign in to comment.