<commit_before><commit_msg>Add tests<commit_after>import os
import unittest

import browse


REPO_PATH = os.path.dirname(os.path.realpath(__file__))
TEST_DIR = 'testdir'
TEST_DIR_PATH = os.path.join(REPO_PATH, 'testdir')
GIT_URLS = [
    (
        '<EMAIL>:albertyw/git-browse',
        None,
        'https://github.com/albertyw/git-browse'
    ),
    (
        '<EMAIL>:albertyw/git-browse.git',
        None,
        'https://github.com/albertyw/git-browse'
    ),
    (
        '<EMAIL>:albertyw/asdf._zxcv',
        None,
        'https://github.com/albertyw/asdf._zxcv'
    ),
    (
        '<EMAIL>:asdf._zxcv/git-browse',
        None,
        'https://github.com/asdf._zxcv/git-browse'
    ),
    (
        'https://github.com/albertyw/git-browse.git',
        None,
        'https://github.com/albertyw/git-browse'
    ),
    (
        'https://github.com/albertyw/git-browse',
        None,
        'https://github.com/albertyw/git-browse'
    ),
    (
        '<EMAIL>:albertyw/git-browse',
        'README.md',
        'https://github.com/albertyw/git-browse/blob/master/README.md'
    ),
    (
        '<EMAIL>:albertyw/git-browse',
        TEST_DIR,
        'https://github.com/albertyw/git-browse/tree/master/testdir/'
    ),
]


class TestGitURLs(unittest.TestCase):
    def setUp(self):
        os.mkdir(TEST_DIR_PATH)

    def tearDown(self):
        os.rmdir(TEST_DIR_PATH)


def generate_test(*test_data):
    git_url, target_path, host_url = test_data

    def test(self):
        host = browse.parse_git_url(git_url)
        sys_argv = ['git-browse.py']
        if target_path:
            sys_argv.append(target_path)
        focus_object = browse.get_focus_object(sys_argv, REPO_PATH)
        url = host.get_url(focus_object)
        self.assertEqual(host_url, url)
    return test


for i, test_data in enumerate(GIT_URLS):
    test_method = generate_test(*test_data)
    test_method.__name__ = 'test_git_url_%s' % i
    setattr(TestGitURLs, test_method.__name__, test_method)
{'fraction_non_alphanumeric': 0.14435564435564435, 'fraction_numerical': 0.0, 'mean_word_length': 2.383445945945946, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 10, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, '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': '1020246', 'n_tokens_mistral': 782, 'n_tokens_neox': 759, 'n_words': 84}