def test_custom_char_line_import(self):

        # we need to write some data to the path first, using defaults
        data_path = resource_filename('tespy.data', 'char_lines.json')

        with open(data_path) as f:
            raw_data = json.loads(f.read())

        data = raw_data['heat exchanger']['kA_char2']
        with open(os.path.join(self.path, 'char_lines.json'), 'w') as outfile:
            json.dump(data, outfile)

        char_original = load_default_char('heat exchanger', 'kA_char2',
                                          'EVAPORATING FLUID', char_line)
        char_custom = load_custom_char('EVAPORATING FLUID', char_line)

        shutil.rmtree(self.path, ignore_errors=True)

        x_cond = np.array_equal(char_original.x, char_custom.x)
        y_cond = np.array_equal(char_original.y, char_custom.y)

        msg = ('The x values from the custom characteristic line ' +
               str(char_custom.x) + ' must be identical to the x values from '
               'the default characteristic line ' + str(char_original.x) + ' '
               'as these have been duplicated before load.')
        eq_(True, x_cond, msg)

        msg = ('The y values from the custom characteristic line ' +
               str(char_custom.y) + ' must be identical to the y values from '
               'the default characteristic line ' + str(char_original.y) + ' '
               'as these have been duplicated before load.')
        eq_(True, y_cond, msg)
Example #2
0
def test_custom_char_map_import():
    """Test importing a custom characteristc map."""

    # we need to write some data to the path first, using defaults
    data_path = resource_filename('tespy.data', 'char_maps.json')
    path = extend_basic_path('data')
    tmp_path = extend_basic_path('tmp_dir_for_testing')

    if os.path.exists(path):
        for f in os.listdir(path):
            shutil.copy(src=path + '/' + f, dst=tmp_path)

    with open(data_path) as f:
        raw_data = json.loads(f.read())

    data = raw_data['compressor']['char_map']
    with open(os.path.join(path, 'char_maps.json'), 'w') as outfile:
        json.dump(data, outfile)

    char_original = load_default_char('compressor', 'char_map', 'DEFAULT',
                                      compressor_map)
    char_custom = load_custom_char('DEFAULT', compressor_map)

    x_cond = np.array_equal(char_original.x, char_custom.x)
    y_cond = np.array_equal(char_original.y, char_custom.y)
    z1_cond = np.array_equal(char_original.z1, char_custom.z1)
    z2_cond = np.array_equal(char_original.z2, char_custom.z2)

    shutil.rmtree(path, ignore_errors=True)

    if os.path.exists(tmp_path):
        path = extend_basic_path('data')
        for f in os.listdir(tmp_path):
            shutil.copy(src=tmp_path + '/' + f, dst=path)

        shutil.rmtree(tmp_path, ignore_errors=True)

    msg = ('The x values from the custom characteristic line ' +
           str(char_custom.x) + ' must be identical to the x values from '
           'the default characteristic line ' + str(char_original.x) + ' '
           'as these have been duplicated before load.')
    assert x_cond is True, msg

    msg = ('The y values from the custom characteristic line ' +
           str(char_custom.y) + ' must be identical to the y values from '
           'the default characteristic line ' + str(char_original.y) + ' '
           'as these have been duplicated before load.')
    assert y_cond is True, msg

    msg = ('The z1 values from the custom characteristic line ' +
           str(char_custom.z1) + ' must be identical to the z1 values from '
           'the default characteristic line ' + str(char_original.z1) + ' '
           'as these have been duplicated before load.')
    assert z1_cond is True, msg

    msg = ('The z2 values from the custom characteristic line ' +
           str(char_custom.z2) + ' must be identical to the z2 values from '
           'the default characteristic line ' + str(char_original.z2) + ' '
           'as these have been duplicated before load.')
    assert z2_cond is True, msg
Example #3
0
def test_missing_char_map_files():
    """Test missing files."""
    path = extend_basic_path('data')
    tmp_path = extend_basic_path('tmp_dir_for_testing')

    if os.path.exists(path):
        for f in os.listdir(path):
            shutil.copy(src=path + '/' + f, dst=tmp_path)

        shutil.rmtree(path, ignore_errors=True)

    with raises(FileNotFoundError):
        load_custom_char('some other stuff', char_map)

    if os.path.exists(tmp_path):
        for f in os.listdir(tmp_path):
            shutil.copy(src=tmp_path + '/' + f, dst=path)

        shutil.rmtree(tmp_path, ignore_errors=True)
    def test_custom_char_map_import(self):
        """Test importing a custom characteristc map."""

        # we need to write some data to the path first, using defaults
        data_path = resource_filename('tespy.data', 'char_maps.json')

        with open(data_path) as f:
            raw_data = json.loads(f.read())

        data = raw_data['compressor']['char_map']
        with open(os.path.join(self.path, 'char_maps.json'), 'w') as outfile:
            json.dump(data, outfile)

        char_original = load_default_char('compressor', 'char_map', 'DEFAULT',
                                          compressor_map)
        char_custom = load_custom_char('DEFAULT', compressor_map)

        x_cond = np.array_equal(char_original.x, char_custom.x)
        y_cond = np.array_equal(char_original.y, char_custom.y)
        z1_cond = np.array_equal(char_original.z1, char_custom.z1)
        z2_cond = np.array_equal(char_original.z2, char_custom.z2)

        shutil.rmtree(self.path, ignore_errors=True)

        msg = ('The x values from the custom characteristic line ' +
               str(char_custom.x) + ' must be identical to the x values from '
               'the default characteristic line ' + str(char_original.x) + ' '
               'as these have been duplicated before load.')
        eq_(True, x_cond, msg)

        msg = ('The y values from the custom characteristic line ' +
               str(char_custom.y) + ' must be identical to the y values from '
               'the default characteristic line ' + str(char_original.y) + ' '
               'as these have been duplicated before load.')
        eq_(True, y_cond, msg)

        msg = ('The z1 values from the custom characteristic line ' +
               str(char_custom.z1) +
               ' must be identical to the z1 values from '
               'the default characteristic line ' + str(char_original.z1) + ' '
               'as these have been duplicated before load.')
        eq_(True, z1_cond, msg)

        msg = ('The z2 values from the custom characteristic line ' +
               str(char_custom.z2) +
               ' must be identical to the z2 values from '
               'the default characteristic line ' + str(char_original.z2) + ' '
               'as these have been duplicated before load.')
        eq_(True, z2_cond, msg)
Example #5
0
def test_custom_CharLine_import():
    """Test importing a custom characteristc lines."""

    # we need to write some data to the path first, using defaults
    data_path = resource_filename('tespy.data', 'char_lines.json')
    path = extend_basic_path('data')
    tmp_path = extend_basic_path('tmp_dir_for_testing')

    if os.path.exists(path):
        for f in os.listdir(path):
            shutil.copy(src=path + '/' + f, dst=tmp_path)

    with open(data_path) as f:
        raw_data = json.loads(f.read())

    data = raw_data['heat exchanger']['kA_char2']
    with open(os.path.join(path, 'char_lines.json'), 'w') as outfile:
        json.dump(data, outfile)

    char_original = load_default_char('heat exchanger', 'kA_char2',
                                      'EVAPORATING FLUID', CharLine)
    char_custom = load_custom_char('EVAPORATING FLUID', CharLine)

    shutil.rmtree(path, ignore_errors=True)

    if os.path.exists(tmp_path):
        path = extend_basic_path('data')
        for f in os.listdir(tmp_path):
            shutil.copy(src=tmp_path + '/' + f, dst=path)

        shutil.rmtree(tmp_path, ignore_errors=True)

    x_cond = np.array_equal(char_original.x, char_custom.x)
    y_cond = np.array_equal(char_original.y, char_custom.y)

    msg = ('The x values from the custom characteristic line ' +
           str(char_custom.x) + ' must be identical to the x values from '
           'the default characteristic line ' + str(char_original.x) + ' '
           'as these have been duplicated before load.')
    assert x_cond, msg

    msg = ('The y values from the custom characteristic line ' +
           str(char_custom.y) + ' must be identical to the y values from '
           'the default characteristic line ' + str(char_original.y) + ' '
           'as these have been duplicated before load.')
    assert y_cond, msg
Example #6
0
def test_missing_char_files():
    load_custom_char('some other stuff', char_map)
Example #7
0
def test_missing_char_files():
    load_custom_char('stuff', char_line)