# 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
        def get_sheet_by_name(self, name):
            return DummyWs()

    with open(os.path.join(DATADIR, 'reader', 'workbook.xml')) as handle:
        content = handle.read()
    named_ranges = read_named_ranges(content, DummyWB())
    eq_(["My Sheeet!$D$8"], [str(range) for range in named_ranges])

def test_oddly_shaped_named_ranges():

    ranges_counts = ((4, 'TEST_RANGE'),
                     (3, 'TRAP_1'),
                     (13, 'TRAP_2'))

    def check_ranges(ws, count, range_name):

        eq_(count, len(ws.range(range_name)))

    wb = load_workbook(os.path.join(DATADIR, 'genuine', 'merge_range.xlsx'),
                       use_iterators = False)

    ws = wb.worksheets[0]

    for count, range_name in ranges_counts:

        yield check_ranges, ws, count, range_name


def test_merged_cells_named_range():


# 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

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

    with open(os.path.join(DATADIR, 'reader', 'workbook.xml')) as handle:
        content = handle.read()
    named_ranges = read_named_ranges(content, DummyWB())
    eq_(["My Sheeet!$D$8"], [str(range) for range in named_ranges])

def test_oddly_shaped_named_ranges():

    ranges_counts = ((4, 'TEST_RANGE'),
                     (3, 'TRAP_1'),
                     (13, 'TRAP_2'))

    def check_ranges(ws, count, range_name):

        eq_(count, len(ws.range(range_name)))

    wb = load_workbook(os.path.join(DATADIR, 'genuine', 'merge_range.xlsx'),
                       use_iterators = False)

    ws = wb.worksheets[0]

    for count, range_name in ranges_counts:

        yield check_ranges, ws, count, range_name


def test_merged_cells_named_range():


    wb = load_workbook(os.path.join(DATADIR, 'genuine', 'merge_range.xlsx'),