# Path: cis/parse.py
# def parse_args(arguments=None):
#     """
#     Parse the arguments given. If no arguments are given, then used the command line arguments.
#     Returns a dictionary contains the parsed arguments
#     """
#     parser = initialise_top_parser()
#     if arguments is None:
#         # sys.argv[0] is the name of the script itself
#         arguments = sys.argv[1:]
#     main_args = parser.parse_args(arguments)
#     # TODO I don't really like this as I have to specify the aliases twice...
#     if main_args.command in aliases.keys():
#         main_args.command = aliases[main_args.command]
# 
#     # Firstly deal with logging verbosity - in case we log anything in the validation
#     # The 'screen' handler is the first in the list
#     if main_args.quiet:
#         logging.getLogger().handlers[0].setLevel(logging.ERROR)
#     elif main_args.verbose == 1:
#         logging.getLogger().handlers[0].setLevel(logging.INFO)
#     elif main_args.verbose == 2:
#         logging.getLogger().handlers[0].setLevel(logging.DEBUG)
# 
#     main_args = validators[main_args.command](main_args, parser)
# 
#     return main_args
# 
# def expand_file_list(filenames, parser):
#     """
# 
#     :param filenames: A string which is a comma seperated list of filenames, wildcarded filenames or directories
#     :param parser: A reference parser for raising errors on
#     :return: A flat list of files which exist - with no duplicate
#     """
#     from cis.data_io.data_reader import expand_filelist
# 
#     if not filenames:
#         parser.error("Please specify at least one filename")
# 
#     try:
#         file_set = expand_filelist(filenames)
#     except ValueError as e:
#         parser.error(str(e))
# 
#     # Check we matched at least one file
#     if file_set:
#         logging.info("Identified input file list: " + str(file_set))
#     else:
#         parser.error("No files found which match: " + str(filenames))
# 
#     return file_set
# 
# Path: cis/plotting/plot.py
# def format_units(units):
# def get_label(common_data, units=True):
# def _try_coord(data, coord_dict):
# def get_axis(d, axis, name=None):
# def set_x_axis_as_time(ax):
#     def format_datetime(x, pos=None):
# def _get_extent(ax):
# def _test_natural_earth_available():
# def drawcoastlines(ax, coastlinescolour):
# def drawbluemarble(ax):
# def get_best_map_ticks(ax, transform=None):
# def set_map_ticks(ax, xticks, yticks, transform=None):
# def add_color_bar(ax, mappable, vstep, logv, cbarscale, cbarorient, cbarlabel):
# def basic_plot(data, how=None, ax=None, xaxis=None, yaxis=None, projection=None, central_longitude=0.0,
#                label=None, *args, **kwargs):
# def multilayer_plot(data_list, how=None, ax=None, yaxis=None, layer_opts=None, *args, **kwargs):
# def taylor_plot(data_list, ax=None, layer_opts=None, *args, **kwargs):


import argparse
import os
    import re
        import os
from unittest import TestCase
from mock import patch
from hamcrest import is_, assert_that, contains_inanyorder
from nose.tools import eq_, raises
from cis.parse import parse_args, expand_file_list
from cis.plotting.plot import plot_types
        from tempfile import mkdtemp
        from shutil import rmtree
        from cis.parse import _file_already_exists_and_no_overwrite
        from argparse import Namespace
        from tempfile import NamedTemporaryFile
        from cis.parse import _file_already_exists_and_no_overwrite
        from argparse import Namespace
        from tempfile import NamedTemporaryFile
        from cis.parse import _file_already_exists_and_no_overwrite
        from argparse import Namespace
        from tempfile import NamedTemporaryFile
        from cis.parse import _file_already_exists_and_no_overwrite
        from argparse import Namespace
        from tempfile import NamedTemporaryFile
        from cis.parse import _output_file_matches_an_input_file
        from argparse import Namespace
        from tempfile import NamedTemporaryFile
            # Choose no to not overwrite - return True
            with patch('six.moves.input', return_value='n'):
                assert _file_already_exists_and_no_overwrite(arguments)

            # Choose yes, eventually
            with patch('six.moves.input', side_effect=['blah', 'blah', 'y']):
                assert not _file_already_exists_and_no_overwrite(arguments)

            # Choose the default (no)
            with patch('six.moves.input', return_value=''):
                assert _file_already_exists_and_no_overwrite(arguments)

            # Choose the default, eventually
            with patch('six.moves.input', side_effect=['yo', 'nope', '']):
                assert _file_already_exists_and_no_overwrite(arguments)


class TestParsePlot(ParseTestFiles):
    """
    Tests specific to the plot command
    """

    def test_can_specify_valid_chart_type(self):
        args = ["plot", "var:" + self.escaped_test_directory_files[0], "--type",
                list(plot_types.keys())[0]]
        parse_args(args)

    def test_should_raise_error_with_an_invalid_chart_type(self):
        try:
            args = ["plot", "var:" + self.escaped_test_directory_files[0], "--type", "dfgdfgdfgdfgdfgdf"]

# Path: cis/parse.py
# def parse_args(arguments=None):
#     """
#     Parse the arguments given. If no arguments are given, then used the command line arguments.
#     Returns a dictionary contains the parsed arguments
#     """
#     parser = initialise_top_parser()
#     if arguments is None:
#         # sys.argv[0] is the name of the script itself
#         arguments = sys.argv[1:]
#     main_args = parser.parse_args(arguments)
#     # TODO I don't really like this as I have to specify the aliases twice...
#     if main_args.command in aliases.keys():
#         main_args.command = aliases[main_args.command]
# 
#     # Firstly deal with logging verbosity - in case we log anything in the validation
#     # The 'screen' handler is the first in the list
#     if main_args.quiet:
#         logging.getLogger().handlers[0].setLevel(logging.ERROR)
#     elif main_args.verbose == 1:
#         logging.getLogger().handlers[0].setLevel(logging.INFO)
#     elif main_args.verbose == 2:
#         logging.getLogger().handlers[0].setLevel(logging.DEBUG)
# 
#     main_args = validators[main_args.command](main_args, parser)
# 
#     return main_args
# 
# def expand_file_list(filenames, parser):
#     """
# 
#     :param filenames: A string which is a comma seperated list of filenames, wildcarded filenames or directories
#     :param parser: A reference parser for raising errors on
#     :return: A flat list of files which exist - with no duplicate
#     """
#     from cis.data_io.data_reader import expand_filelist
# 
#     if not filenames:
#         parser.error("Please specify at least one filename")
# 
#     try:
#         file_set = expand_filelist(filenames)
#     except ValueError as e:
#         parser.error(str(e))
# 
#     # Check we matched at least one file
#     if file_set:
#         logging.info("Identified input file list: " + str(file_set))
#     else:
#         parser.error("No files found which match: " + str(filenames))
# 
#     return file_set
# 
# Path: cis/plotting/plot.py
# def format_units(units):
# def get_label(common_data, units=True):
# def _try_coord(data, coord_dict):
# def get_axis(d, axis, name=None):
# def set_x_axis_as_time(ax):
#     def format_datetime(x, pos=None):
# def _get_extent(ax):
# def _test_natural_earth_available():
# def drawcoastlines(ax, coastlinescolour):
# def drawbluemarble(ax):
# def get_best_map_ticks(ax, transform=None):
# def set_map_ticks(ax, xticks, yticks, transform=None):
# def add_color_bar(ax, mappable, vstep, logv, cbarscale, cbarorient, cbarlabel):
# def basic_plot(data, how=None, ax=None, xaxis=None, yaxis=None, projection=None, central_longitude=0.0,
#                label=None, *args, **kwargs):
# def multilayer_plot(data_list, how=None, ax=None, yaxis=None, layer_opts=None, *args, **kwargs):
# def taylor_plot(data_list, ax=None, layer_opts=None, *args, **kwargs):


# Path: cis/test/unit/test_parse.py
import argparse
import os
    import re
        import os
from unittest import TestCase
from mock import patch
from hamcrest import is_, assert_that, contains_inanyorder
from nose.tools import eq_, raises
from cis.parse import parse_args, expand_file_list
from cis.plotting.plot import plot_types
        from tempfile import mkdtemp
        from shutil import rmtree
        from cis.parse import _file_already_exists_and_no_overwrite
        from argparse import Namespace
        from tempfile import NamedTemporaryFile
        from cis.parse import _file_already_exists_and_no_overwrite
        from argparse import Namespace
        from tempfile import NamedTemporaryFile
        from cis.parse import _file_already_exists_and_no_overwrite
        from argparse import Namespace
        from tempfile import NamedTemporaryFile
        from cis.parse import _file_already_exists_and_no_overwrite
        from argparse import Namespace
        from tempfile import NamedTemporaryFile
        from cis.parse import _output_file_matches_an_input_file
        from argparse import Namespace
        from tempfile import NamedTemporaryFile

            # Choose no to not overwrite - return True
            with patch('six.moves.input', return_value='n'):
                assert _file_already_exists_and_no_overwrite(arguments)

            # Choose yes, eventually
            with patch('six.moves.input', side_effect=['blah', 'blah', 'y']):
                assert not _file_already_exists_and_no_overwrite(arguments)

            # Choose the default (no)
            with patch('six.moves.input', return_value=''):
                assert _file_already_exists_and_no_overwrite(arguments)

            # Choose the default, eventually
            with patch('six.moves.input', side_effect=['yo', 'nope', '']):
                assert _file_already_exists_and_no_overwrite(arguments)


class TestParsePlot(ParseTestFiles):
    """
    Tests specific to the plot command
    """

    def test_can_specify_valid_chart_type(self):
        args = ["plot", "var:" + self.escaped_test_directory_files[0], "--type",
                list(plot_types.keys())[0]]
        parse_args(args)

    def test_should_raise_error_with_an_invalid_chart_type(self):
        try:
            args = ["plot", "var:" + self.escaped_test_directory_files[0], "--type", "dfgdfgdfgdfgdfgdf"]

            parse_args(args)