Skip to content
This repository has been archived by the owner on Jun 3, 2024. It is now read-only.

add check that dash was correctly imported and exit with helpful message if failed #177

Merged
merged 3 commits into from
Mar 30, 2018
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions dash_core_components/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
from __future__ import print_function as _

import os as _os
import sys as _sys

import dash as _dash

from .version import __version__

if not hasattr(_dash, 'development'):
print("Dash was not successfully imported. Make sure you don't have a file "
"named \n'dash.py' in your current directory.", file=_sys.stderr)
_sys.exit(1)

_current_path = _os.path.dirname(_os.path.abspath(__file__))

_components = _dash.development.component_loader.load_components(
Expand Down
23 changes: 23 additions & 0 deletions test/test_dash_import.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import os
import unittest


class TestDashImport(unittest.TestCase):
def setUp(self):
with open('dash.py', 'w') as f:
pass

def tearDown(self):
try:
os.remove('dash.py')
os.remove('dash.pyc')
except OSError:
pass

def test_dash_import(self):
"""Test that program exits if the wrong dash module was imported"""

with self.assertRaises(SystemExit) as cm:
import dash_core_components

self.assertEqual(cm.exception.code, 1)
2 changes: 2 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,5 @@ basepython={env:TOX_PYTHON_27}
commands =
python --version
python -m unittest test.test_integration
python -m unittest test.test_dash_import