# Path: bashhub/bashhub.py
# @click.group(context_settings=CONTEXT_SETTINGS)
# @click.option('-V',
#               '--version',
#               default=False,
#               is_flag=True,
#               callback=print_version,
#               help='Display version',
#               expose_value=False,
#               is_eager=True)
# def bashhub():
#     """Bashhub command line client"""
#     pass
# 
# Path: bashhub/version.py

# 
# Path: bashhub/bashhub.py
# def print_version(ctx, param, value):
# def bashhub():
# def version():
# def off(is_global):
# def on(local):
# def save(command, path, pid, process_start_time, exit_status):
# def setup():
# def status():
# def help(ctx):
# def filter(command, regex):
# def update(version):
# def util():
# def update_system_info():
# def parsedate(date_string):
# def unix_time_to_epoc_millis(unix_time):
# def main():
# CONTEXT_SETTINGS = dict(help_option_names=['-h', '--help'])
# 
# Path: bashhub/bashhub.py
# def print_version(ctx, param, value):
# def bashhub():
# def version():
# def off(is_global):
# def on(local):
# def save(command, path, pid, process_start_time, exit_status):
# def setup():
# def status():
# def help(ctx):
# def filter(command, regex):
# def update(version):
# def util():
# def update_system_info():
# def parsedate(date_string):
# def unix_time_to_epoc_millis(unix_time):
# def main():
# CONTEXT_SETTINGS = dict(help_option_names=['-h', '--help'])


import os
import click
from click.testing import CliRunner
from bashhub.bashhub import bashhub
from bashhub.version import __version__
from bashhub.bashhub import rest_client
from bashhub.bashhub import bashhub_globals




def test_bashhub_save():
    def print_failed(command):
        print("Failed")
        pass

    rest_client.save_command = print_failed

    runner = CliRunner()
    args = ['save', 'echo "Running bashhub tests"', '/tmp', '1', '100000', '1']

    ignored_command = ['save', 'echo "Running bashhub tests" #ignore', '/tmp',
                       '1', '100000', '1']

    # Should omit saving if save_commands is set
    bashhub_globals.BH_SAVE_COMMANDS = False
    result = runner.invoke(bashhub, args)
    assert '' == result.output

    bashhub_globals.BH_SAVE_COMMANDS = True

    # Should omit saving if #ignore is set
    result = runner.invoke(bashhub, ignored_command)
    assert '' == result.output

    # Should omit saving a command if BH_FILTER regex is set
    bashhub_globals.BH_FILTER = 'echo'

# Path: bashhub/bashhub.py
# @click.group(context_settings=CONTEXT_SETTINGS)
# @click.option('-V',
#               '--version',
#               default=False,
#               is_flag=True,
#               callback=print_version,
#               help='Display version',
#               expose_value=False,
#               is_eager=True)
# def bashhub():
#     """Bashhub command line client"""
#     pass
# 
# Path: bashhub/version.py

# 
# Path: bashhub/bashhub.py
# def print_version(ctx, param, value):
# def bashhub():
# def version():
# def off(is_global):
# def on(local):
# def save(command, path, pid, process_start_time, exit_status):
# def setup():
# def status():
# def help(ctx):
# def filter(command, regex):
# def update(version):
# def util():
# def update_system_info():
# def parsedate(date_string):
# def unix_time_to_epoc_millis(unix_time):
# def main():
# CONTEXT_SETTINGS = dict(help_option_names=['-h', '--help'])
# 
# Path: bashhub/bashhub.py
# def print_version(ctx, param, value):
# def bashhub():
# def version():
# def off(is_global):
# def on(local):
# def save(command, path, pid, process_start_time, exit_status):
# def setup():
# def status():
# def help(ctx):
# def filter(command, regex):
# def update(version):
# def util():
# def update_system_info():
# def parsedate(date_string):
# def unix_time_to_epoc_millis(unix_time):
# def main():
# CONTEXT_SETTINGS = dict(help_option_names=['-h', '--help'])


# Path: tests/test_bashhub.py
import os
import click
from click.testing import CliRunner
from bashhub.bashhub import bashhub
from bashhub.version import __version__
from bashhub.bashhub import rest_client
from bashhub.bashhub import bashhub_globals





def test_bashhub_save():
    def print_failed(command):
        print("Failed")
        pass

    rest_client.save_command = print_failed

    runner = CliRunner()
    args = ['save', 'echo "Running bashhub tests"', '/tmp', '1', '100000', '1']

    ignored_command = ['save', 'echo "Running bashhub tests" #ignore', '/tmp',
                       '1', '100000', '1']

    # Should omit saving if save_commands is set
    bashhub_globals.BH_SAVE_COMMANDS = False
    result = runner.invoke(bashhub, args)
    assert '' == result.output

    bashhub_globals.BH_SAVE_COMMANDS = True

    # Should omit saving if #ignore is set
    result = runner.invoke(bashhub, ignored_command)
    assert '' == result.output

    # Should omit saving a command if BH_FILTER regex is set
    bashhub_globals.BH_FILTER = 'echo'

    result = runner.invoke(bashhub, args)