<commit_before>#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""
test_powertool
----------------------------------

Tests for `powertool` module.
"""

import pytest

from contextlib import contextmanager
from click.testing import CliRunner

from powertool import powertool
from powertool import cli
try:
    from unittest.mock import patch, mock_open
except ImportError:
    from mock import patch, mock_open


@pytest.fixture
def response():
    """Sample pytest fixture.
    See more at: http://doc.pytest.org/en/latest/fixture.html
    """
    # import requests
    # return requests.get('https://github.com/audreyr/cookiecutter-pypackage')


def test_content(response):
    """Sample pytest test function with the pytest fixture as an argument.
    """
    # from bs4 import BeautifulSoup
    # assert 'GitHub' in BeautifulSoup(response.content).title.string
def test_command_line_interface():
    runner = CliRunner()
    result = runner.invoke(cli.main, {})
    # assert result.exit_code == 0
    assert '--help' in result.output
    # assert 'powertool.cli.main' in result.output
    help_result = runner.invoke(cli.main, ['--help'])
    assert help_result.exit_code == 0
    assert '--help' in help_result.output


@patch('json.load')
def test_list_should_return_machines(jsonload):
    jsonload.return_value = {
        "aa:bb:cc:dd:ee:ff" : {
            "hostname" : "host",
            "username" : "user",
            "broadcast" : "192.168.1.1"
        }
    }
    runner = CliRunner()
    result = runner.invoke(cli.main, ["list"])
    assert u'user@host' in result.output
    assert u'aa:bb:cc:dd:ee:ff' in result.output
    assert u'192.168.1.1' in result.output


@patch('json.load')
@patch('json.dump')
def test_list_should_remove_machine(jsondump, jsonload):
    jsonload.return_value = {
        "aa:bb:cc:dd:ee:ff" : {
            "hostname" : "host",
            "username" : "user",
            "broadcast" : "192.168.1.1"
        },
        "aa:bb:cc:dd:ee:ee" : {
            "hostname" : "host2",
            "username" : "user",
            "broadcast" : "192.168.1.1"
        }
    }
    runner = CliRunner()
    mo = mock_open()
    with patch('powertool.cli.open', mo):
        runner.invoke(cli.main, ["rm", "--host", "host"])<commit_msg>try unicode fix<commit_after>#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""
test_powertool
----------------------------------

Tests for `powertool` module.
"""

import pytest

from contextlib import contextmanager
from click.testing import CliRunner

from powertool import powertool
from powertool import cli
try:
    from unittest.mock import patch, mock_open
except ImportError:
    from mock import patch, mock_open


@pytest.fixture
def response():
    """Sample pytest fixture.
    See more at: http://doc.pytest.org/en/latest/fixture.html
    """
    # import requests
    # return requests.get('https://github.com/audreyr/cookiecutter-pypackage')


def test_content(response):
    """Sample pytest test function with the pytest fixture as an argument.
    """
    # from bs4 import BeautifulSoup
    # assert 'GitHub' in BeautifulSoup(response.content).title.string
def test_command_line_interface():
    runner = CliRunner()
    result = runner.invoke(cli.main, {})
    # assert result.exit_code == 0
    assert '--help' in result.output
    # assert 'powertool.cli.main' in result.output
    help_result = runner.invoke(cli.main, ['--help'])
    assert help_result.exit_code == 0
    assert '--help' in help_result.output


@patch('json.load')
def test_list_should_return_machines(jsonload):
    jsonload.return_value = {
        u"aa:bb:cc:dd:ee:ff" : {
            u"hostname" : u"host",
            u"username" : u"user",
            u"broadcast" : u"192.168.1.1"
        }
    }
    runner = CliRunner()
    result = runner.invoke(cli.main, ["list"])
    assert u'user@host' in result.output
    assert u'aa:bb:cc:dd:ee:ff' in result.output
    assert u'192.168.1.1' in result.output


@patch('json.load')
@patch('json.dump')
def test_rm_should_remove_machine(jsondump, jsonload):
    jsonload.return_value = {
        "aa:bb:cc:dd:ee:ff" : {
            "hostname" : "host",
            "username" : "user",
            "broadcast" : "192.168.1.1"
        },
        "aa:bb:cc:dd:ee:ee" : {
            "hostname" : "host2",
            "username" : "user",
            "broadcast" : "192.168.1.1"
        }
    }
    runner = CliRunner()
    mo = mock_open()
    with patch('powertool.cli.open', mo):
        runner.invoke(cli.main, ["rm", "--host", "host"])
{'fraction_non_alphanumeric': 0.1565179160255001, 'fraction_numerical': 0.016267311497032314, 'mean_word_length': 2.660498793242156, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 8, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3480183', 'n_tokens_mistral': 1537, 'n_tokens_neox': 1507, 'n_words': 323}