Example #1
0
    def test_subscript_references(self):
        from pysd.vensim2py import get_equation_components
        self.assertEqual(
            get_equation_components(r'constant [Sub1, Sub2] = 10, 12; 14, 16;'),
            {'expr': '10, 12; 14, 16;', 'kind': 'component', 'subs': ['Sub1', 'Sub2'],
             'real_name': 'constant'}
        )

        self.assertEqual(
            get_equation_components(r'function [Sub1] = other function[Sub1]'),
            {'expr': 'other function[Sub1]', 'kind': 'component', 'subs': ['Sub1'],
             'real_name': 'function'}
        )

        self.assertEqual(
            get_equation_components(r'constant ["S1,b", "S1,c"] = 1, 2; 3, 4;'),
            {'expr': '1, 2; 3, 4;', 'kind': 'component', 'subs': ['"S1,b"', '"S1,c"'],
             'real_name': 'constant'}
        )

        self.assertEqual(
            get_equation_components(r'constant ["S1=b", "S1=c"] = 1, 2; 3, 4;'),
            {'expr': '1, 2; 3, 4;', 'kind': 'component', 'subs': ['"S1=b"', '"S1=c"'],
             'real_name': 'constant'}
        )
Example #2
0
    def test_pathological_names(self):
        from pysd.vensim2py import get_equation_components
        self.assertEqual(
            get_equation_components(r'"silly-string" = 25'),
            {'expr': '25', 'kind': 'component', 'subs': [], 'real_name': '"silly-string"'}
        )

        self.assertEqual(
            get_equation_components(r'"pathological\\-string" = 25'),
            {'expr': '25', 'kind': 'component', 'subs': [],
             'real_name': r'"pathological\\-string"'}
        )
Example #3
0
    def test_lookup_definitions(self):
        from pysd.vensim2py import get_equation_components
        self.assertEqual(
            get_equation_components(r'table([(0,-1)-(45,1)],(0,0),(5,0))'),
            {'expr': '([(0,-1)-(45,1)],(0,0),(5,0))', 'kind': 'lookup', 'subs': [],
             'real_name': 'table'}
        )

        self.assertEqual(
            get_equation_components(r'table2 ([(0,-1)-(45,1)],(0,0),(5,0))'),
            {'expr': '([(0,-1)-(45,1)],(0,0),(5,0))', 'kind': 'lookup', 'subs': [],
             'real_name': 'table2'}
        )
Example #4
0
    def test_whitespace_handling(self):
        """ Whitespaces should be shortened to a single space """
        from pysd.vensim2py import get_equation_components
        self.assertEqual(
            get_equation_components(r'''constant\t =
                                                        \t25\t '''),
            {'expr': '25', 'kind': 'component', 'subs': [], 'real_name': 'constant'}
        )

        # test eliminating vensim's line continuation character
        self.assertEqual(
            get_equation_components(r"""constant [Sub1, \\
                                     Sub2] = 10, 12; 14, 16;"""),
            {'expr': '10, 12; 14, 16;', 'kind': 'component', 'subs': ['Sub1', 'Sub2'],
             'real_name': 'constant'}
        )
Example #5
0
 def test_subscript_definition_parsing(self):
     from pysd.vensim2py import get_equation_components
     self.assertEqual(
         get_equation_components(r'''Sub1: Entry 1, Entry 2, Entry 3 '''),
         {'expr': None, 'kind': 'subdef', 'subs': ['Entry 1', 'Entry 2', 'Entry 3'],
          'real_name': 'Sub1'}
     )
Example #6
0
    def test_pathological_names(self):
        from pysd.vensim2py import get_equation_components
        self.assertEqual(
            get_equation_components(r'"silly-string" = 25'), {
                'expr': '25',
                'kind': 'component',
                'subs': [],
                'real_name': '"silly-string"'
            })

        self.assertEqual(
            get_equation_components(r'"pathological\\-string" = 25'), {
                'expr': '25',
                'kind': 'component',
                'subs': [],
                'real_name': r'"pathological\\-string"'
            })
Example #7
0
    def test_lookup_definitions(self):
        from pysd.vensim2py import get_equation_components
        self.assertEqual(
            get_equation_components(r'table([(0,-1)-(45,1)],(0,0),(5,0))'), {
                'expr': '([(0,-1)-(45,1)],(0,0),(5,0))',
                'kind': 'lookup',
                'subs': [],
                'real_name': 'table'
            })

        self.assertEqual(
            get_equation_components(r'table2 ([(0,-1)-(45,1)],(0,0),(5,0))'), {
                'expr': '([(0,-1)-(45,1)],(0,0),(5,0))',
                'kind': 'lookup',
                'subs': [],
                'real_name': 'table2'
            })
Example #8
0
 def test_basics(self):
     from pysd.vensim2py import get_equation_components
     self.assertEqual(get_equation_components(r'constant = 25'), {
         'expr': '25',
         'kind': 'component',
         'subs': [],
         'real_name': 'constant'
     })
Example #9
0
 def test_equals_handling(self):
     """ Parse cases with equal signs within the expression """
     from pysd.vensim2py import get_equation_components
     self.assertEqual(
         get_equation_components(r'Boolean = IF THEN ELSE(1 = 1, 1, 0)'),
         {'expr': 'IF THEN ELSE(1 = 1, 1, 0)', 'kind': 'component', 'subs': [],
          'real_name': 'Boolean'}
     )
Example #10
0
 def test_subscript_definition_parsing(self):
     from pysd.vensim2py import get_equation_components
     self.assertEqual(
         get_equation_components(r'''Sub1: Entry 1, Entry 2, Entry 3 '''), {
             'expr': None,
             'kind': 'subdef',
             'subs': ['Entry 1', 'Entry 2', 'Entry 3'],
             'real_name': 'Sub1'
         })
Example #11
0
 def test_equals_handling(self):
     """ Parse cases with equal signs within the expression """
     from pysd.vensim2py import get_equation_components
     self.assertEqual(
         get_equation_components(r'Boolean = IF THEN ELSE(1 = 1, 1, 0)'), {
             'expr': 'IF THEN ELSE(1 = 1, 1, 0)',
             'kind': 'component',
             'subs': [],
             'real_name': 'Boolean'
         })
Example #12
0
    def test_whitespace_handling(self):
        """ Whitespaces should be shortened to a single space """
        from pysd.vensim2py import get_equation_components
        self.assertEqual(
            get_equation_components(r'''constant\t =
                                                        \t25\t '''), {
                'expr': '25',
                'kind': 'component',
                'subs': [],
                'real_name': 'constant'
            })

        # test eliminating vensim's line continuation character
        self.assertEqual(
            get_equation_components(r"""constant [Sub1, \\
                                     Sub2] = 10, 12; 14, 16;"""), {
                'expr': '10, 12; 14, 16;',
                'kind': 'component',
                'subs': ['Sub1', 'Sub2'],
                'real_name': 'constant'
            })
Example #13
0
    def test_subscript_references(self):
        from pysd.vensim2py import get_equation_components
        self.assertEqual(
            get_equation_components(
                r'constant [Sub1, Sub2] = 10, 12; 14, 16;'), {
                    'expr': '10, 12; 14, 16;',
                    'kind': 'component',
                    'subs': ['Sub1', 'Sub2'],
                    'real_name': 'constant'
                })

        self.assertEqual(
            get_equation_components(r'function [Sub1] = other function[Sub1]'),
            {
                'expr': 'other function[Sub1]',
                'kind': 'component',
                'subs': ['Sub1'],
                'real_name': 'function'
            })

        self.assertEqual(
            get_equation_components(
                r'constant ["S1,b", "S1,c"] = 1, 2; 3, 4;'), {
                    'expr': '1, 2; 3, 4;',
                    'kind': 'component',
                    'subs': ['"S1,b"', '"S1,c"'],
                    'real_name': 'constant'
                })

        self.assertEqual(
            get_equation_components(
                r'constant ["S1=b", "S1=c"] = 1, 2; 3, 4;'), {
                    'expr': '1, 2; 3, 4;',
                    'kind': 'component',
                    'subs': ['"S1=b"', '"S1=c"'],
                    'real_name': 'constant'
                })
Example #14
0
 def test_basics(self):
     from pysd.vensim2py import get_equation_components
     self.assertEqual(
         get_equation_components(r'constant = 25'),
         {'expr': '25', 'kind': 'component', 'subs': [], 'real_name': 'constant'}
     )