Example #1
0
    def test_init(self):
        """Test normalization of name input."""
        test1 = lynames.LyName('TEST name ')
        assert test1.name == 'test_name', "name should be normalized"
        assert test1.number is None, "Number should be None if not specified"

        test2 = lynames.LyName('  another_test-name')
        assert test2.name == 'another_test_name', "name should be normalized"
        assert test2.number is None, "Number should be None if not specified"
Example #2
0
def test_ins_part(tmpdir, jinja_env, test_ins, test_ins3, piece1,
                  piece2, piano):
    """Tests rendering an instrument part."""
    instemplate = jinja_env.get_template('ins_part.ly')
    lyglobals = lynames.LyName(name='global')
    flags1 = {
        'key_in_partname': False,
        'compress_full_bar_rests': True,
    }
    flags2 = {
        'key_in_partname': True,
        'compress_full_bar_rests': False
    }
    render1 = instemplate.render(piece=piece1, instrument=test_ins,
                                 lyglobal=lyglobals, flags=flags1,
                                 filename='inspart_test1.ly')
    render2 = instemplate.render(piece=piece2, instrument=test_ins3,
                                 lyglobal=lyglobals, flags=flags2,
                                 filename='inspart_test2.ly')
    render3 = instemplate.render(piece=piece1, instrument=piano,
                                 lyglobal=lyglobals, flags=flags1,
                                 filename='piano_part.ly')
    with open(Path(tmpdir, 'inspart_test1.ly'), 'w') as part:
        part.write(render1)
    with open(Path(tmpdir, 'inspart_test2.ly'), 'w') as part:
        part.write(render2)
    with open(Path(tmpdir, 'piano_part.ly'), 'w') as part:
        part.write(render3)

    with open(Path(tmpdir, 'inspart_test1.ly'), 'r') as part:
        part_test1 = part.read()
    with open(Path(tmpdir, 'inspart_test2.ly'), 'r') as part:
        part_test2 = part.read()
    with open(Path(tmpdir, 'piano_part.ly'), 'r') as part:
        part_test3 = part.read()

    assert '\\version' in part_test1
    assert '\\include "defs.ily"' in part_test1
    assert '\\violin_one_first_mov' in part_test1
    assert '\\global_second_mov' in part_test1
    assert '\\compressFullBarRests' in part_test1

    assert '\\version' in part_test2
    assert '\\include "defs.ily"' in part_test2
    assert '\\clarinet_in_bb_first_mov' in part_test2
    assert '\\clarinet_in_bb_fourth_mov' in part_test2
    assert '\\global_second_mov' in part_test2
    assert '\\compressFullBarRests' not in part_test2
    assert 'Op. 15' in part_test2

    assert '\\version' in part_test3
    assert '\\include "defs.ily"' in part_test3
    assert '\\piano_first_mov_LH' in part_test3
    assert '\\piano_third_mov_RH' in part_test3
    assert 'PianoStaff' in part_test3
Example #3
0
def build(file_path, target_dir, extra_includes, key_in_partname,
          compress_full_bar_rests):
    target_dir = Path(target_dir)
    if not file_path:
        possible_configs = [
            possible for possible in os.listdir(target_dir)
            if '.yaml' in possible or '.yml' in possible
        ]
        if len(possible_configs) == 0:
            print("No config file found. Please specify one with -f")
            raise SystemExit(1)
        elif len(possible_configs) == 1:
            print(f"Config file found: {possible_configs[0]}")
            use = prompt("Use this config? ",
                         default='Y',
                         validator=YNValidator())
            if answered_yes(use):
                file_path = possible_configs[0]
            else:
                print(
                    "Please specify a config file with -f or change to the directory it is in."
                )
                raise SystemExit(1)
    piece = yaml_interface.read_config(Path(file_path))
    # piece = info.Piece.load(config_data)
    lyglobal = lynames.LyName('global')
    include_paths = []
    flags = {
        "key_in_partname": key_in_partname,
        "compress_full_bar_rests": compress_full_bar_rests
    }
    global_file = render.make_global(lyglobal, piece, location=target_dir)
    include_paths.extend(global_file)
    for instrument in piece.instruments:
        new_includes = render.make_instrument(instrument=instrument,
                                              lyglobal=lyglobal,
                                              piece=piece,
                                              location=target_dir,
                                              flags=flags)
        include_paths.extend(new_includes)
    render.render_includes(include_paths,
                           piece,
                           extra_includes=extra_includes,
                           location=target_dir)
    render.render_defs(piece, location=target_dir)
    render.render_score(piece,
                        piece.instruments,
                        lyglobal,
                        path_prefix=Path('.'))
Example #4
0
def test_score(piece1, jinja_env, instrument_list1, piano, tmpdir):
    """Test the score template."""
    instruments = instrument_list1.append(piano)
    lyglobal = lynames.LyName(name='global')
    template = jinja_env.get_template('score.ly')
    render = template.render(piece=piece1, filename='score.ly',
                             lyglobal=lyglobal, instruments=instrument_list1)
    scorepath = Path(tmpdir, 'score.ly')
    with open(scorepath, 'w') as scorefile:
        scorefile.write(render)

    with open(scorepath, 'r') as scorefile:
        scorerender = scorefile.read()

    assert 'Test Piece' in scorerender
    assert '\\version' in scorerender
    assert '\\violin_one_first_mov' in scorerender
    assert '\\global_first_mov' in scorerender
    assert '\\violoncello_two_third_mov' in scorerender
    assert '\\piano_first_mov_LH' in scorerender
    assert 'shortInstrumentName = "Cl."' in scorerender
    assert 'instrumentName = "Violin I"' in scorerender
Example #5
0
def testlyname2():
    test2 = lynames.LyName('test')
    test2.number = 2
    test2._numword = 'two'
    return test2
Example #6
0
def testlyname1():
    return lynames.LyName('global')
Example #7
0
def global_ins():
    """An object for global info."""
    return lynames.LyName(name='global')
Example #8
0
def lyglobal():
    return lynames.LyName('global')