コード例 #1
0
def test_seq_simple():
    test_string = dals("""
    a_seq:
      - 1
      - 2
      - 3
    """)
    assert test_string == yaml_round_trip_dump({'a_seq': [1, 2, 3]})
コード例 #2
0
def test_dump():
    obj = dict([
        ('a_seq', [1, 2, 3]),
        ('a_map', {
            'a_key': 'a_value'
        }),
    ])
    assert obj == yaml_round_trip_load(yaml_round_trip_dump(obj))
コード例 #3
0
ファイル: test_config.py プロジェクト: marcelotrevisani/conda
def test_set_rc_without_user_rc():

    if os.path.exists(sys_rc_path):
        # Backup system rc_config
        with open(sys_rc_path, 'r') as fh:
            sys_rc_config_backup = yaml_round_trip_load(fh)
        restore_sys_rc_config_backup = True
    else:
        restore_sys_rc_config_backup = False

    if os.path.exists(user_rc_path):
        # Backup user rc_config
        with open(user_rc_path, 'r') as fh:
            user_rc_config_backup = yaml_round_trip_load(fh)
        # Remove user rc_path
        os.remove(user_rc_path)
        restore_user_rc_config_backup = True
    else:
        restore_user_rc_config_backup = False

    try:
        # Write custom system sys_rc_config
        with open(sys_rc_path, 'w') as rc:
            rc.write(yaml_round_trip_dump({'channels': ['conda-forge']}))
    except (OSError, IOError):
        # In case, we don't have writing right to the system rc config file
        pytest.skip("No writing right to root prefix.")

    # This would create a user rc_config
    stdout, stderr, return_code = run_command(Commands.CONFIG, '--add',
                                              'channels', 'test')
    assert stdout == stderr == ''
    assert yaml_round_trip_load(_read_test_condarc(user_rc_path)) == {
        'channels': ['test', 'conda-forge']
    }

    if restore_user_rc_config_backup:
        # Restore previous user rc_config
        with open(user_rc_path, 'w') as rc:
            rc.write(yaml_round_trip_dump(user_rc_config_backup))
    if restore_sys_rc_config_backup:
        # Restore previous system rc_config
        with open(sys_rc_path, 'w') as rc:
            rc.write(yaml_round_trip_dump(sys_rc_config_backup))
コード例 #4
0
ファイル: test_config.py プロジェクト: marcelotrevisani/conda
def test_custom_multichannels_prepend():
    with make_temp_condarc() as rc:
        stdout, stderr, return_code = run_command(Commands.CONFIG, '--file',
                                                  rc, '--prepend',
                                                  'custom_multichannels.foo',
                                                  'bar')
        assert stdout == stderr == ''
        assert _read_test_condarc(rc) == yaml_round_trip_dump(
            {"custom_multichannels": {
                "foo": ["bar"]
            }})
コード例 #5
0
def test_yaml_complex():
    test_string = dals("""
    single_bool: false
    single_str: no

    # comment here
    a_seq_1:
      - 1
      - 2
      - 3

    a_seq_2:
      - 1  # with comment
      - two: 2
      - 3

    a_map:
      # comment
      field1: true
      field2: yes

    # final comment
    """)

    python_structure = {
        'single_bool': False,
        'single_str': 'no',
        'a_seq_1': [
            1,
            2,
            3,
        ],
        'a_seq_2': [
            1,
            {
                'two': 2
            },
            3,
        ],
        'a_map': {
            'field1': True,
            'field2': 'yes',
        },
    }

    loaded_from_string = yaml_round_trip_load(test_string)
    assert python_structure == loaded_from_string

    dumped_from_load = yaml_round_trip_dump(loaded_from_string)
    print(dumped_from_load)
    assert dumped_from_load == test_string
コード例 #6
0
ファイル: test_config.py プロジェクト: marcelotrevisani/conda
def test_custom_multichannels_prepend_duplicate():
    custom_multichannels_expected = yaml_round_trip_dump(
        {"custom_multichannels": {
            "foo": ["bar"]
        }})
    with make_temp_condarc(custom_multichannels_expected) as rc:
        stdout, stderr, return_code = run_command(Commands.CONFIG, '--file',
                                                  rc, '--prepend',
                                                  'custom_multichannels.foo',
                                                  'bar')
        assert stdout == ''
        assert stderr.strip(
        ) == "Warning: 'bar' already in 'custom_multichannels.foo' list, moving to the top"
        assert _read_test_condarc(rc) == custom_multichannels_expected
コード例 #7
0
def test_map():
    test_string = dals("""
    a_map:
      a_key: a_value
    """)
    assert test_string == yaml_round_trip_dump({'a_map': {'a_key': 'a_value'}})