Exemplo n.º 1
0
def test_columnize_long():
    """Test columnize with inputs longer than the display window"""
    text.columnize(["a" * 81, "b" * 81], displaywidth=80)
    size = 11
    items = [l * size for l in "abc"]
    out = text.columnize(items, displaywidth=size - 1)
    nt.assert_equals(out, "\n".join(items + [""]))
Exemplo n.º 2
0
def test_columnize_long():
    """Test columnize with inputs longer than the display window"""
    text.columnize(['a' * 81, 'b' * 81], displaywidth=80)
    size = 11
    items = [l * size for l in 'abc']
    out = text.columnize(items, displaywidth=size - 1)
    nt.assert_equals(out, '\n'.join(items + ['']))
Exemplo n.º 3
0
def test_columnize_long():
    """Test columnize with inputs longer than the display window"""
    text.columnize(['a'*81, 'b'*81], displaywidth=80)
    size = 11
    items = [l*size for l in 'abc']
    out = text.columnize(items, displaywidth=size-1)
    nt.assert_equals(out, '\n'.join(items+['']))
Exemplo n.º 4
0
def test_columnize():
    """Basic columnize tests."""
    size = 5
    items = [l * size for l in 'abc']
    out = text.columnize(items, displaywidth=80)
    nt.assert_equals(out, 'aaaaa  bbbbb  ccccc\n')
    out = text.columnize(items, displaywidth=10)
    nt.assert_equals(out, 'aaaaa  ccccc\nbbbbb\n')
Exemplo n.º 5
0
def test_columnize():
    """Basic columnize tests."""
    size = 5
    items = [l*size for l in 'abc']
    out = text.columnize(items, displaywidth=80)
    nt.assert_equals(out, 'aaaaa  bbbbb  ccccc\n')
    out = text.columnize(items, displaywidth=10)
    nt.assert_equals(out, 'aaaaa  ccccc\nbbbbb\n')
Exemplo n.º 6
0
def test_columnize_long():
    """Test columnize with inputs longer than the display window"""
    size = 11
    items = [l*size for l in 'abc']
    for row_first in [True, False]:
        out = text.columnize(items, row_first=row_first, displaywidth=size - 1)
        assert out == "\n".join(items + [""]), "row_first={0}".format(row_first)
Exemplo n.º 7
0
def test_columnize_medium():
    """Test with inputs than shouldn't be wider than 80"""
    size = 40
    items = [l*size for l in 'abc']
    for row_first in [True, False]:
        out = text.columnize(items, row_first=row_first, displaywidth=80)
        assert out == "\n".join(items + [""]), "row_first={0}".format(row_first)
Exemplo n.º 8
0
def test_columnize_long():
    """Test columnize with inputs longer than the display window"""
    size = 11
    items = [l*size for l in 'abc']
    for row_first in [True, False]:
        out = text.columnize(items, row_first=row_first, displaywidth=size-1)
        nt.assert_equal(out, '\n'.join(items+['']), "row_first={0}".format(row_first))
Exemplo n.º 9
0
def test_columnize_medium():
    """Test with inputs than shouldn't be wider than 80"""
    size = 40
    items = [l*size for l in 'abc']
    for row_first in [True, False]:
        out = text.columnize(items, row_first=row_first, displaywidth=80)
        nt.assert_equal(out, '\n'.join(items+['']), "row_first={0}".format(row_first))
Exemplo n.º 10
0
 def show_items(self, cursor, items):
     """ Shows the completion widget with 'items' at the position specified
         by 'cursor'.
     """
     if not items:
         return
     self.cancel_completion()
     strng = text.columnize(items)
     self._console_widget._fill_temporary_buffer(cursor, strng, html=False)
Exemplo n.º 11
0
 def show_items(self, cursor, items):
     """ Shows the completion widget with 'items' at the position specified
         by 'cursor'.
     """
     if not items:
         return
     self.cancel_completion()
     strng = text.columnize(items)
     self._console_widget._fill_temporary_buffer(cursor, strng, html=False)
Exemplo n.º 12
0
def test_columnize_random():
    """Test with random input to hopfully catch edge case """
    for nitems in [random.randint(2, 70) for i in range(2, 20)]:
        displaywidth = random.randint(20, 200)
        rand_len = [random.randint(2, displaywidth) for i in range(nitems)]
        items = ['x' * l for l in rand_len]
        out = text.columnize(items, displaywidth=displaywidth)
        longer_line = max([len(x) for x in out.split('\n')])
        longer_element = max(rand_len)
        if longer_line > displaywidth:
            print "Columnize displayed something lager than displaywidth : %s " % longer_line
            print "longer element : %s " % longer_element
            print "displaywidth : %s " % displaywidth
            print "number of element : %s " % nitems
            print "size of each element :\n %s" % rand_len
            assert False
Exemplo n.º 13
0
def test_columnize_random():
    """Test with random input to hopfully catch edge case """
    for nitems in [random.randint(2, 70) for i in range(2, 20)]:
        displaywidth = random.randint(20, 200)
        rand_len = [random.randint(2, displaywidth) for i in range(nitems)]
        items = ["x" * l for l in rand_len]
        out = text.columnize(items, displaywidth=displaywidth)
        longer_line = max([len(x) for x in out.split("\n")])
        longer_element = max(rand_len)
        if longer_line > displaywidth:
            print "Columnize displayed something lager than displaywidth : %s " % longer_line
            print "longer element : %s " % longer_element
            print "displaywidth : %s " % displaywidth
            print "number of element : %s " % nitems
            print "size of each element :\n %s" % rand_len
            assert False
Exemplo n.º 14
0
def test_columnize_random():
    """Test with random input to hopfully catch edge case """
    for row_first in [True, False]:
        for nitems in [random.randint(2,70) for i in range(2,20)]:
            displaywidth = random.randint(20,200)
            rand_len = [random.randint(2,displaywidth) for i in range(nitems)]
            items = ['x'*l for l in rand_len]
            out = text.columnize(items, row_first=row_first, displaywidth=displaywidth)
            longer_line = max([len(x) for x in out.split('\n')])
            longer_element = max(rand_len)
            if longer_line > displaywidth:
                print("Columnize displayed something lager than displaywidth : %s " % longer_line)
                print("longer element : %s " % longer_element)
                print("displaywidth : %s " % displaywidth)
                print("number of element : %s " % nitems)
                print("size of each element :\n %s" % rand_len)
                assert False, "row_first={0}".format(row_first)
Exemplo n.º 15
0
def test_columnize_random():
    """Test with random input to hopfully catch edge case """
    for row_first in [True, False]:
        for nitems in [random.randint(2,70) for i in range(2,20)]:
            displaywidth = random.randint(20,200)
            rand_len = [random.randint(2,displaywidth) for i in range(nitems)]
            items = ['x'*l for l in rand_len]
            out = text.columnize(items, row_first=row_first, displaywidth=displaywidth)
            longer_line = max([len(x) for x in out.split('\n')])
            longer_element = max(rand_len)
            if longer_line > displaywidth:
                print("Columnize displayed something lager than displaywidth : %s " % longer_line)
                print("longer element : %s " % longer_element)
                print("displaywidth : %s " % displaywidth)
                print("number of element : %s " % nitems)
                print("size of each element :\n %s" % rand_len)
                assert False, "row_first={0}".format(row_first)
Exemplo n.º 16
0
def test_columnize_random():
    """Test with random input to hopefully catch edge case """
    for row_first in [True, False]:
        for nitems in [random.randint(2,70) for i in range(2,20)]:
            displaywidth = random.randint(20,200)
            rand_len = [random.randint(2,displaywidth) for i in range(nitems)]
            items = ['x'*l for l in rand_len]
            out = text.columnize(items, row_first=row_first, displaywidth=displaywidth)
            longer_line = max([len(x) for x in out.split('\n')])
            longer_element = max(rand_len)
            assert longer_line <= displaywidth, (
                f"Columnize displayed something lager than displaywidth : {longer_line}\n"
                f"longer element : {longer_element}\n"
                f"displaywidth : {displaywidth}\n"
                f"number of element : {nitems}\n"
                f"size of each element : {rand_len}\n"
                f"row_first={row_first}\n"
            )
Exemplo n.º 17
0
def test_columnize_medium():
    """Test with inputs than shouldn't be wider tahn 80 """
    size = 40
    items = [l * size for l in "abc"]
    out = text.columnize(items, displaywidth=80)
    nt.assert_equals(out, "\n".join(items + [""]))
Exemplo n.º 18
0
def test_columnize():
    """Basic columnize tests."""
    size = 5
    items = [l*size for l in 'abcd']

    out = text.columnize(items, displaywidth=80)
    nt.assert_equal(out, 'aaaaa  bbbbb  ccccc  ddddd\n')
    out = text.columnize(items, displaywidth=25)
    nt.assert_equal(out, 'aaaaa  ccccc\nbbbbb  ddddd\n')
    out = text.columnize(items, displaywidth=12)
    nt.assert_equal(out, 'aaaaa  ccccc\nbbbbb  ddddd\n')
    out = text.columnize(items, displaywidth=10)
    nt.assert_equal(out, 'aaaaa\nbbbbb\nccccc\nddddd\n')

    out = text.columnize(items, row_first=True, displaywidth=80)
    nt.assert_equal(out, 'aaaaa  bbbbb  ccccc  ddddd\n')
    out = text.columnize(items, row_first=True, displaywidth=25)
    nt.assert_equal(out, 'aaaaa  bbbbb\nccccc  ddddd\n')
    out = text.columnize(items, row_first=True, displaywidth=12)
    nt.assert_equal(out, 'aaaaa  bbbbb\nccccc  ddddd\n')
    out = text.columnize(items, row_first=True, displaywidth=10)
    nt.assert_equal(out, 'aaaaa\nbbbbb\nccccc\nddddd\n')

    out = text.columnize(items, displaywidth=40, spread=True)
    nt.assert_equal(out, 'aaaaa      bbbbb      ccccc      ddddd\n')
    out = text.columnize(items, displaywidth=20, spread=True)
    nt.assert_equal(out, 'aaaaa          ccccc\nbbbbb          ddddd\n')
    out = text.columnize(items, displaywidth=12, spread=True)
    nt.assert_equal(out, 'aaaaa  ccccc\nbbbbb  ddddd\n')
    out = text.columnize(items, displaywidth=10, spread=True)
    nt.assert_equal(out, 'aaaaa\nbbbbb\nccccc\nddddd\n')
Exemplo n.º 19
0
def test_columnize_medium():
    """Test with inputs than shouldn't be wider tahn 80 """
    size = 40
    items = [l*size for l in 'abc']
    out = text.columnize(items, displaywidth=80)
    nt.assert_equal(out, '\n'.join(items+['']))
Exemplo n.º 20
0
def test_columnize():
    """Basic columnize tests."""
    size = 5
    items = [l * size for l in 'abcd']

    out = text.columnize(items, displaywidth=80)
    nt.assert_equal(out, 'aaaaa  bbbbb  ccccc  ddddd\n')
    out = text.columnize(items, displaywidth=25)
    nt.assert_equal(out, 'aaaaa  ccccc\nbbbbb  ddddd\n')
    out = text.columnize(items, displaywidth=12)
    nt.assert_equal(out, 'aaaaa  ccccc\nbbbbb  ddddd\n')
    out = text.columnize(items, displaywidth=10)
    nt.assert_equal(out, 'aaaaa\nbbbbb\nccccc\nddddd\n')

    out = text.columnize(items, row_first=True, displaywidth=80)
    nt.assert_equal(out, 'aaaaa  bbbbb  ccccc  ddddd\n')
    out = text.columnize(items, row_first=True, displaywidth=25)
    nt.assert_equal(out, 'aaaaa  bbbbb\nccccc  ddddd\n')
    out = text.columnize(items, row_first=True, displaywidth=12)
    nt.assert_equal(out, 'aaaaa  bbbbb\nccccc  ddddd\n')
    out = text.columnize(items, row_first=True, displaywidth=10)
    nt.assert_equal(out, 'aaaaa\nbbbbb\nccccc\nddddd\n')

    out = text.columnize(items, displaywidth=40, spread=True)
    nt.assert_equal(out, 'aaaaa      bbbbb      ccccc      ddddd\n')
    out = text.columnize(items, displaywidth=20, spread=True)
    nt.assert_equal(out, 'aaaaa          ccccc\nbbbbb          ddddd\n')
    out = text.columnize(items, displaywidth=12, spread=True)
    nt.assert_equal(out, 'aaaaa  ccccc\nbbbbb  ddddd\n')
    out = text.columnize(items, displaywidth=10, spread=True)
    nt.assert_equal(out, 'aaaaa\nbbbbb\nccccc\nddddd\n')
Exemplo n.º 21
0
def test_columnize_medium():
    """Test with inputs than shouldn't be wider tahn 80 """
    size = 40
    items = [l * size for l in 'abc']
    out = text.columnize(items, displaywidth=80)
    nt.assert_equals(out, '\n'.join(items + ['']))
Exemplo n.º 22
0
def get_global_training_state(data_path, short_model_name, experiment,
                              checkpoints_path):
    code_dicts = utils.make_lang_code_dicts()
    code_to_name = code_dicts["code_to_name"]
    name_to_code = code_dicts["name_to_code"]

    # Infer task from data path
    if "sentiment" in data_path:
        task = "sentiment"
    else:
        task = "pos"

    # Get full model names
    model_name, full_model_name = model_utils.get_full_model_names(
        short_model_name)
    # Get all languages that belong to the experiment
    all_langs = utils.get_langs(experiment)

    # Sort languages according to their status
    if task == "sentiment" and experiment == "tfm":
        excluded = ["Turkish", "Japanese", "Russian"]
    else:
        excluded = []
    trained_langs = []
    cannot_train_langs = []
    remaining_langs = []
    for lang in all_langs:
        if lang in excluded:
            continue
        # Check if there are train and dev sets available
        elif is_trainable(lang, data_path, task):
            if glob.glob(checkpoints_path + "{}/{}_{}.hdf5".format(
                    name_to_code[lang], model_name, task)):
                trained_langs.append(lang)
            else:
                remaining_langs.append(lang)
        else:
            cannot_train_langs.append(lang)

    # Print status
    if remaining_langs:
        training_lang = remaining_langs[0]
        print("{:<20}".format("Training language:"), training_lang, "\n")
        training_lang = name_to_code[training_lang]
        print(
            columnize(["Already trained:   "] + trained_langs,
                      displaywidth=150))
        print(
            columnize(["Not yet trained:   "] + remaining_langs[1:],
                      displaywidth=150))
        print(
            columnize(["Cannot train:      "] + cannot_train_langs,
                      displaywidth=150))
    else:
        print("No languages remaining", "\n")
        print(
            columnize(["Already trained:   "] + trained_langs,
                      displaywidth=150))
        print(
            columnize(["Cannot train:      "] + cannot_train_langs,
                      displaywidth=150))
        training_lang = None
        if input("Retrain language? ") == "y":
            while training_lang not in all_langs:
                training_lang = input("Language to re-train: ")
            training_lang = name_to_code[training_lang]

    return training_lang