<commit_before># -*- coding: utf-8 -*-
import os
import nose
from nose.tools import assert_equal
from datetime import datetime

from xlwings import xlwings_connect, Range

xl_file1 = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'test1.xlsx')
wb = xlwings_connect(xl_file1)


def test_cell():
    """ Style: Range('A1') """
    params = [('A1', 22),
              ((1,1), 22),
              ('A1', 22.2222),
              ((1,1), 22.2222),
              ('A1', 'Test String'),
              ((1,1), 'Test String'),
              ('A1', u'éöà'),
              ((1,1), u'éöà'),
              ('A2', datetime(1962, 11, 3)),
              ((2,1), datetime(1962, 11, 3)),
              ('A3', datetime(2020, 12, 31, 12, 12, 20)),
              ((3,1), datetime(2020, 12, 31, 12, 12, 20))]
    for param in params:
        yield check_cell, param[0], param[1]


def check_cell(address, value):
        # Active Sheet
        Range(address).value = value
        cell = Range(address).value
        assert_equal(cell, value)

        # Sheetname
        Range('Sheet2', address).value = value
        cell = Range('Sheet2', address).value
        assert_equal(cell, value)

        # Sheetindex
        Range(3, address).value = value
        cell = Range(3, address).value
        assert_equal(cell, value)


if __name__ == '__main__':
    nose.main()<commit_msg>added new tests<commit_after># -*- coding: utf-8 -*-
import os
import nose
from nose.tools import assert_equal
from datetime import datetime
import numpy as np
from numpy.testing import assert_array_equal
from pandas import DataFrame

from xlwings import xlwings_connect, Range

# Connect to test file and make Sheet1 the active sheet
xl_file1 = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'test1.xlsx')
wb = xlwings_connect(xl_file1)
wb.Sheets('Sheet1').Activate()

# Testdata
data = [[1, 2.222, 3.333],
        ['Test1', None, u'éöà'],
        [datetime(1962, 11, 3), datetime(2020, 12, 31, 12, 12, 20), 9.999]]


def test_cell():
    params = [('A1', 22),
              ((1,1), 22),
              ('A1', 22.2222),
              ((1,1), 22.2222),
              ('A1', 'Test String'),
              ((1,1), 'Test String'),
              ('A1', u'éöà'),
              ((1,1), u'éöà'),
              ('A2', datetime(1962, 11, 3)),
              ((2,1), datetime(1962, 11, 3)),
              ('A3', datetime(2020, 12, 31, 12, 12, 20)),
              ((3,1), datetime(2020, 12, 31, 12, 12, 20))]
    for param in params:
        yield check_cell, param[0], param[1]


def check_cell(address, value):
    # Active Sheet
    Range(address).value = value
    cell = Range(address).value
    assert_equal(cell, value)

    # Sheetname
    Range('Sheet2', address).value = value
    cell = Range('Sheet2', address).value
    assert_equal(cell, value)

    # Sheetindex
    Range(3, address).value = value
    cell = Range(3, address).value
    assert_equal(cell, value)


def test_range_address():
    """ Style: Range('A1:C3') """
    address = 'C1:E3'

    # Active Sheet
    Range(address).value = data
    cells = Range(address).value
    assert_equal(cells, data)

    # Sheetname
    Range('Sheet2', address).value = data
    cells = Range('Sheet2', address).value
    assert_equal(cells, data)

    # Sheetindex
    Range(3, address).value = data
    cells = Range(3, address).value
    assert_equal(cells, data)

def test_range_index():
    """ Style: Range((1,1), (3,3)) """
    index1 = (1,3)
    index2 = (3,5)

    # Active Sheet
    Range(index1, index2).value = data
    cells = Range(index1, index2).value
    assert_equal(cells, data)

    # Sheetname
    Range('Sheet2', index1, index2).value = data
    cells = Range('Sheet2', index1, index2).value
    assert_equal(cells, data)

    # Sheetindex
    Range(3, index1, index2).value = data
    cells = Range(3, index1, index2).value
    assert_equal(cells, data)


def test_named_range():
    value = 22.222
    # Active Sheet
    Range('cell_sheet1').value = value
    cells = Range('cell_sheet1').value
    assert_equal(cells, value)

    Range('range_sheet1').value = data
    cells = Range('range_sheet1').value
    assert_equal(cells, data)

    # Sheetname
    Range('Sheet2', 'cell_sheet2').value = value
    cells = Range('Sheet2', 'cell_sheet2').value
    assert_equal(cells, value)

    Range('Sheet2', 'range_sheet2').value = data
    cells = Range('Sheet2', 'range_sheet2').value
    assert_equal(cells, data)

    # Sheetindex
    Range(3, 'cell_sheet3').value = value
    cells = Range(3, 'cell_sheet3').value
    assert_equal(cells, value)

    Range(3, 'range_sheet3').value = data
    cells = Range(3, 'range_sheet3').value
    assert_equal(cells, data)


def test_array():
    numpy_array = np.array([[1.1, 2.2, 3.3], [4.4, 5.5, 6.6], [7.7, 8.8, np.nan]])
    Range('L1').value = numpy_array
    cells = Range('L1:N3', asarray=True).value
    numpy_array = np.where(np.isnan(numpy_array), None, numpy_array)
    assert_array_equal(cells, numpy_array)


def test_table():
    Range('Sheet4', 'A1').value = data
    cells = Range('Sheet4', 'A1').table.value
    assert_equal(cells, data)


def test_clear_content():
    Range('Sheet4', 'G1').value = 22
    Range('Sheet4', 'G1').clear_contents()
    cell = Range('Sheet4', 'G1').value
    assert_equal(cell, None)


def test_clear():
    Range('Sheet4', 'G1').value = 22
    Range('Sheet4', 'G1').clear()
    cell = Range('Sheet4', 'G1').value
    assert_equal(cell, None)


def test_dataframe():
    df = DataFrame({'a': [1, 2, 3.3, np.nan], 'b': ['test1', 'test2', 'test3', np.nan]})
    Range('Sheet5', 'A1').value = df

if __name__ == '__main__':
    nose.main()
{'fraction_non_alphanumeric': 0.16396332863187588, 'fraction_numerical': 0.055888575458392105, 'mean_word_length': 2.82277628032345, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 5, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4781918', 'n_tokens_mistral': 2131, 'n_tokens_neox': 1928, 'n_words': 460}