# Path: openpyxl/tests/helper.py
# DATADIR = os.path.abspath(os.path.join(os.path.dirname(__file__), 'test_data'))
# 
# Path: openpyxl/reader/excel.py
# def load_workbook(filename, use_iterators = False):
#     """Open the given filename and return the workbook
# 
#     :param filename: the path to open
#     :type filename: string
#     
#     :param use_iterators: use lazy load for cells
#     :type use_iterators: bool
# 
#     :rtype: :class:`openpyxl.workbook.Workbook`
#     
#     .. note::
#         
#         When using lazy load, all worksheets will be :class:`openpyxl.reader.iter_worksheet.IterableWorksheet`
#         and the returned workbook will be read-only. 
# 
#     """
# 
#     if isinstance(filename, file):
#         # fileobject must have been opened with 'rb' flag
#         # it is required by zipfile
#         if 'b' not in filename.mode:
#             raise OpenModeError("File-object must be opened in binary mode")
# 
#     try:
#         archive = ZipFile(filename, 'r', ZIP_DEFLATED)
#     except (BadZipfile, RuntimeError, IOError, ValueError), e:
#         raise InvalidFileException(unicode(e))
#     wb = Workbook()
# 
#     if use_iterators:
#         wb._set_optimized_read()
# 
#     try:
#         _load_workbook(wb, archive, filename, use_iterators)
#     except KeyError, e:
#         raise InvalidFileException(unicode(e))
#     finally:
#         archive.close()
#     return wb


import os.path
from nose.tools import eq_, assert_raises
from openpyxl.tests.helper import DATADIR
from openpyxl.namedrange import split_named_range
from openpyxl.reader.workbook import read_named_ranges
from openpyxl.shared.exc import NamedRangeException
from openpyxl.reader.excel import load_workbook
# 3rd-party imports

# package imports


def test_split():
    eq_([('My Sheet', '$D$8'), ], split_named_range("'My Sheet'!$D$8"))


def test_split_no_quotes():
    eq_([('HYPOTHESES', '$B$3:$L$3'), ], split_named_range('HYPOTHESES!$B$3:$L$3'))


def test_bad_range_name():
    assert_raises(NamedRangeException, split_named_range, 'HYPOTHESES$B$3')


def test_read_named_ranges():

    class DummyWs(object):
        title = 'My Sheeet'

        def __str__(self):
            return self.title

    class DummyWB(object):

        def get_sheet_by_name(self, name):
            return DummyWs()


# Path: openpyxl/tests/helper.py
# DATADIR = os.path.abspath(os.path.join(os.path.dirname(__file__), 'test_data'))
# 
# Path: openpyxl/reader/excel.py
# def load_workbook(filename, use_iterators = False):
#     """Open the given filename and return the workbook
# 
#     :param filename: the path to open
#     :type filename: string
#     
#     :param use_iterators: use lazy load for cells
#     :type use_iterators: bool
# 
#     :rtype: :class:`openpyxl.workbook.Workbook`
#     
#     .. note::
#         
#         When using lazy load, all worksheets will be :class:`openpyxl.reader.iter_worksheet.IterableWorksheet`
#         and the returned workbook will be read-only. 
# 
#     """
# 
#     if isinstance(filename, file):
#         # fileobject must have been opened with 'rb' flag
#         # it is required by zipfile
#         if 'b' not in filename.mode:
#             raise OpenModeError("File-object must be opened in binary mode")
# 
#     try:
#         archive = ZipFile(filename, 'r', ZIP_DEFLATED)
#     except (BadZipfile, RuntimeError, IOError, ValueError), e:
#         raise InvalidFileException(unicode(e))
#     wb = Workbook()
# 
#     if use_iterators:
#         wb._set_optimized_read()
# 
#     try:
#         _load_workbook(wb, archive, filename, use_iterators)
#     except KeyError, e:
#         raise InvalidFileException(unicode(e))
#     finally:
#         archive.close()
#     return wb


# Path: openpyxl/tests/test_named_range.py
import os.path
from nose.tools import eq_, assert_raises
from openpyxl.tests.helper import DATADIR
from openpyxl.namedrange import split_named_range
from openpyxl.reader.workbook import read_named_ranges
from openpyxl.shared.exc import NamedRangeException
from openpyxl.reader.excel import load_workbook

# 3rd-party imports

# package imports


def test_split():
    eq_([('My Sheet', '$D$8'), ], split_named_range("'My Sheet'!$D$8"))


def test_split_no_quotes():
    eq_([('HYPOTHESES', '$B$3:$L$3'), ], split_named_range('HYPOTHESES!$B$3:$L$3'))


def test_bad_range_name():
    assert_raises(NamedRangeException, split_named_range, 'HYPOTHESES$B$3')


def test_read_named_ranges():

    class DummyWs(object):
        title = 'My Sheeet'

        def __str__(self):
            return self.title

    class DummyWB(object):

        def get_sheet_by_name(self, name):
            return DummyWs()


    with open(os.path.join(DATADIR, 'reader', 'workbook.xml')) as handle: