simphony / simphony-metadata

[LEGACY] This repository contains the metadata definitions used in SimPhoNy project.
BSD 2-Clause "Simplified" License
0 stars 0 forks source link

Code generator combining PR 8 and PR 16 #17

Closed kitchoi closed 8 years ago

kitchoi commented 8 years ago

Please try the following upon checking out the branch. You should notice that there are some failures. Fixing these failures require adding missing entries in cuba.yml and simphony_metadata.yml

$ pip install -r dev_requirements.txt
$ python setup.py develop
$ simphony-meta-generate meta_class simphony_metadata/yaml_files/simphony_metadata.yml simphony_metadata/scripts/tests/meta_class -O --test
$ simphony-meta-generate keywords simphony_metadata/yaml_files/cuba.yml simphony_metadata/scripts/tests/keywords.py
$ simphony-meta-generate cuba_enum simphony_metadata/yaml_files/cuba.yml simphony_metadata/yaml_files/simphony_metadata.yml simphony_metadata/scripts/tests/cuba.py
$ python -m unittest discover -v -p test*

TODO:

@roigcarlo please take a look.

@ahashibon could you try this out and fill in the missing cuba's please?

@mehdisadeghi I have a setup.py and .travis.yml here, but I don't have admin right on travis, could you set it up please?

Thanks.

kitchoi commented 8 years ago

You probably notice the following warnings (I would prefer it to be an error later when we finalise this generator)

$ simphony-meta-generate meta_class simphony_metadata/yaml_files/simphony_metadata.yml simphony_metadata/scripts/tests/meta_class -O --tests
UserWarning: DISSIPATION_FORCE is SKIPPED because its parent CUBA.FORCE is not defined in CUDS_KEYS
UserWarning: COULOMB_FRICTION_FORCE is SKIPPED because its parent CUBA.FORCE is not defined in CUDS_KEYS
UserWarning: SJKR_COHESION_FORCE is SKIPPED because its parent CUBA.FORCE is not defined in CUDS_KEYS

I am not sure whether the yaml file should change, or what we should do if the yaml file set the parent to a non CUDS item.

mehdisadeghi commented 8 years ago

Travis is ready.

mehdisadeghi commented 8 years ago

For me --tests option is not recognized.

kitchoi commented 8 years ago

Oops, my typo, it is --test

kitchoi commented 8 years ago

Depends on #20

kitchoi commented 8 years ago

@mehdisadeghi The generator is ready. I would leave "populate the docstring for every attribute in a class" for later. Please try the generator and if this is good to merge, please do so. The generated code would need to be reformatted using auto formatter such as yapf in order to pass flake8 test on simphony-common.

mehdisadeghi commented 8 years ago

@kitchoi I am already in the middle of it!

Thanks for the good job!

kitchoi commented 8 years ago

@mehdisadeghi Hold on, I found a small problem with the data attribute setter, let me fix it.

mehdisadeghi commented 8 years ago

@kitchoi OK! I'll come back to it later.

kitchoi commented 8 years ago

Done.

mehdisadeghi commented 8 years ago

I cloned the code and did the following:

pip install -r dev_requirements.txt
$ python setup.py develop
$ simphony-meta-generate meta_class yaml_files/simphony_metadata.yml simphony_metadata/scripts/tests/meta_class -O
$ simphony-meta-generate keywords yaml_files/cuba.yml simphony_metadata/scripts/tests/keywords.py
$ simphony-meta-generate cuba_enum yaml_files/cuba.yml yaml_files/simphony_metadata.yml simphony_metadata/scripts/tests/cuba.py
$ python -m unittest discover -v -p test*

All tests pass except one:

======================================================================
ERROR: simphony_metadata.scripts.tests.test_validation (unittest.loader.ModuleImportFailure)
----------------------------------------------------------------------
ImportError: Failed to import test module: simphony_metadata.scripts.tests.test_validation
Traceback (most recent call last):
  File "/usr/lib/python2.7/unittest/loader.py", line 254, in _find_tests
    module = self._get_module_from_name(name)
  File "/usr/lib/python2.7/unittest/loader.py", line 232, in _get_module_from_name
    __import__(name)
  File "simphony_metadata/scripts/tests/test_validation.py", line 8, in <module>
    from .meta_class import api
  File "simphony_metadata/scripts/tests/meta_class/api.py", line 1, in <module>
    from .engine import Engine
  File "simphony_metadata/scripts/tests/meta_class/engine.py", line 4, in <module>
    from .software_tool import SoftwareTool
  File "simphony_metadata/scripts/tests/meta_class/software_tool.py", line 4, in <module>
    from .cuds_item import CUDSItem
  File "simphony_metadata/scripts/tests/meta_class/cuds_item.py", line 10, in <module>
    class CUDSItem(object):
  File "simphony_metadata/scripts/tests/meta_class/cuds_item.py", line 15, in CUDSItem
    cuba_key = CUBA.CUDS_ITEM
  File "/usr/local/lib/python2.7/dist-packages/enum/__init__.py", line 390, in __getattr__
    raise AttributeError(name)
AttributeError: CUDS_ITEM

Am I missing something?

mehdisadeghi commented 8 years ago

I tried to patch CUBA imports and I got a different errors upon testing:

The dirty patch in test_validation.py:

with patch('simphony.core.cuba.CUBA', CUBA):
    with patch('simphony.core.data_container.CUBA', CUBA):
        from .meta_class import api
        from .keywords import KEYWORDS

The result:

root@c6bdfdcdc0a9:~/meta/simphony_metadata/simphony_metadata/scripts# python -m unittest discover > log
....E/root/meta/simphony_metadata/simphony_metadata/scripts/tests/meta_class/validation.py:166: UserWarning: Value is a string, its shape is not validated. Please fix the cuba.yml shape syntax.
  warnings.warn('Value is a string, its shape is not validated. '
./root/meta/simphony_metadata/simphony_metadata/scripts/tests/meta_class/validation.py:181: UserWarning: ELECTROSTATIC_FIELD is not defined in CUBA keyword or meta data
  warnings.warn(message.format(key.upper()))
/root/meta/simphony_metadata/simphony_metadata/scripts/tests/meta_class/validation.py:181: UserWarning: DESCRIPTION is not defined in CUBA keyword or meta data
  warnings.warn(message.format(key.upper()))
FF../root/meta/simphony_metadata/simphony_metadata/scripts/tests/meta_class/validation.py:181: UserWarning: INITIAL_VISCOSITY is not defined in CUBA keyword or meta data
  warnings.warn(message.format(key.upper()))
/root/meta/simphony_metadata/simphony_metadata/scripts/tests/meta_class/validation.py:181: UserWarning: LINEAR_CONSTANT is not defined in CUBA keyword or meta data
  warnings.warn(message.format(key.upper()))
/root/meta/simphony_metadata/simphony_metadata/scripts/tests/meta_class/validation.py:181: UserWarning: MAXIMUM_VISCOSITY is not defined in CUBA keyword or meta data
  warnings.warn(message.format(key.upper()))
/root/meta/simphony_metadata/simphony_metadata/scripts/tests/meta_class/validation.py:181: UserWarning: POWER_LAW_INDEX is not defined in CUBA keyword or meta data
  warnings.warn(message.format(key.upper()))
/root/meta/simphony_metadata/simphony_metadata/scripts/tests/meta_class/validation.py:181: UserWarning: RELAXATION_TIME is not defined in CUBA keyword or meta data
  warnings.warn(message.format(key.upper()))
/root/meta/simphony_metadata/simphony_metadata/scripts/tests/meta_class/validation.py:181: UserWarning: MINIMUM_VISCOSITY is not defined in CUBA keyword or meta data
  warnings.warn(message.format(key.upper()))
F..F...F...../root/meta/simphony_metadata/simphony_metadata/scripts/tests/meta_class/validation.py:181: UserWarning: SURFACE_TENSION is not defined in CUBA keyword or meta data
  warnings.warn(message.format(key.upper()))
../root/meta/simphony_metadata/simphony_metadata/scripts/tests/meta_class/validation.py:181: UserWarning: MINOR is not defined in CUBA keyword or meta data
  warnings.warn(message.format(key.upper()))
/root/meta/simphony_metadata/simphony_metadata/scripts/tests/meta_class/validation.py:181: UserWarning: PATCH is not defined in CUBA keyword or meta data
  warnings.warn(message.format(key.upper()))
/root/meta/simphony_metadata/simphony_metadata/scripts/tests/meta_class/validation.py:181: UserWarning: MAJOR is not defined in CUBA keyword or meta data
  warnings.warn(message.format(key.upper()))
/root/meta/simphony_metadata/simphony_metadata/scripts/tests/meta_class/validation.py:181: UserWarning: FULL is not defined in CUBA keyword or meta data
  warnings.warn(message.format(key.upper()))
F.....F...
======================================================================
ERROR: test_error_validate_cuba_keyword (tests.test_validation.TestValidation)
Test for TypeError for invalid CUBA keyword value
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/mock.py", line 1201, in patched
    return func(*args, **keywargs)
  File "/root/meta/simphony_metadata/simphony_metadata/scripts/tests/test_validation.py", line 98, in test_error_validate_cuba_keyword
    type=KEYWORDS[cuba_name.upper()].dtype,
KeyError: 'CUBA.MATERIAL'

======================================================================
FAIL: test_Cfd (tests.test_meta_class.TestMetaClass)
Test for Cfd
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/mock.py", line 1201, in patched
    return func(*args, **keywargs)
  File "/root/meta/simphony_metadata/simphony_metadata/scripts/tests/test_meta_class.py", line 192, in test_Cfd
    self.check_cuds_component(meta_obj)
  File "/root/meta/simphony_metadata/simphony_metadata/scripts/tests/test_meta_class.py", line 76, in check_cuds_component
    self.assertIsInstance(instance.description, str)
AssertionError: 1 is not an instance of <type 'str'>

======================================================================
FAIL: test_ComputationalMethod (tests.test_meta_class.TestMetaClass)
Test for ComputationalMethod
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/mock.py", line 1201, in patched
    return func(*args, **keywargs)
  File "/root/meta/simphony_metadata/simphony_metadata/scripts/tests/test_meta_class.py", line 207, in test_ComputationalMethod
    self.check_cuds_component(meta_obj)
  File "/root/meta/simphony_metadata/simphony_metadata/scripts/tests/test_meta_class.py", line 76, in check_cuds_component
    self.assertIsInstance(instance.description, str)
AssertionError: 1 is not an instance of <type 'str'>

======================================================================
FAIL: test_Dem (tests.test_meta_class.TestMetaClass)
Test for Dem
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/mock.py", line 1201, in patched
    return func(*args, **keywargs)
  File "/root/meta/simphony_metadata/simphony_metadata/scripts/tests/test_meta_class.py", line 247, in test_Dem
    self.check_cuds_component(meta_obj)
  File "/root/meta/simphony_metadata/simphony_metadata/scripts/tests/test_meta_class.py", line 76, in check_cuds_component
    self.assertIsInstance(instance.description, str)
AssertionError: 1 is not an instance of <type 'str'>

======================================================================
FAIL: test_EmptyBoundaryCondition (tests.test_meta_class.TestMetaClass)
Test for EmptyBoundaryCondition
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/mock.py", line 1201, in patched
    return func(*args, **keywargs)
  File "/root/meta/simphony_metadata/simphony_metadata/scripts/tests/test_meta_class.py", line 258, in test_EmptyBoundaryCondition
    self.check_cuds_component(meta_obj)
  File "/root/meta/simphony_metadata/simphony_metadata/scripts/tests/test_meta_class.py", line 76, in check_cuds_component
    self.assertIsInstance(instance.description, str)
AssertionError: 1 is not an instance of <type 'str'>

======================================================================
FAIL: test_LennardJones_6_12 (tests.test_meta_class.TestMetaClass)
Test validation code using LennardJones_6_12
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/mock.py", line 1201, in patched
    return func(*args, **keywargs)
  File "/root/meta/simphony_metadata/simphony_metadata/scripts/tests/test_meta_class.py", line 233, in test_LennardJones_6_12
    meta_obj.material = [1, 2]
AssertionError: TypeError not raised

======================================================================
FAIL: test_Version (tests.test_meta_class.TestMetaClass)
Test for Version
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/mock.py", line 1201, in patched
    return func(*args, **keywargs)
  File "/root/meta/simphony_metadata/simphony_metadata/scripts/tests/test_meta_class.py", line 267, in test_Version
    self.assertIsInstance(meta_obj.minor, str)
AssertionError: 1 is not an instance of <type 'str'>

======================================================================
FAIL: test_cuds_components_properties (tests.test_meta_class.TestMetaClass)
Test the properties of CUDSComponent
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/mock.py", line 1201, in patched
    return func(*args, **keywargs)
  File "/root/meta/simphony_metadata/simphony_metadata/scripts/tests/test_meta_class.py", line 145, in test_cuds_components_properties
    self.check_cuds_component(meta_obj)
  File "/root/meta/simphony_metadata/simphony_metadata/scripts/tests/test_meta_class.py", line 76, in check_cuds_component
    self.assertIsInstance(instance.description, str)
AssertionError: 1 is not an instance of <type 'str'>

----------------------------------------------------------------------
Ran 35 tests in 0.018s

FAILED (failures=7, errors=1)