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

Commit

Permalink
add check that dash was correctly imported and exit with helpful mess…
Browse files Browse the repository at this point in the history
…age if failed (#177)

* add check that dash was imported and exit with useful message if not

* added test to check sys.exit(1) called when dash not import correctly

* fix wrong module name
  • Loading branch information
ned2 authored and chriddyp committed Mar 30, 2018
1 parent 1cc0fed commit c2099c8
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
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

0 comments on commit c2099c8

Please sign in to comment.