コード例 #1
0
 def test_unlabeled_foreach_series(self):
     """ Sequences are repeated for each item in the 'foreach' series. """
     assert list(
         parser.generate_commands(
             yaml.load("""
         - foreach: [A,B]
         - echo test{{A,B}}
     """))) == [('echo testA', {}), ('echo testB', {})]
コード例 #2
0
 def test_features(self):
     """ Features and command are separated """
     assert list(
         parser.generate_commands(
             yaml.load('- my_command: {name: my_name}'))) == [('my_command',
                                                               {
                                                                   'name':
                                                                   'my_name'
                                                               })]
コード例 #3
0
 def test_nested_foreach_sequences_with_same_name_error(self):
     """ A series label cannot be used in nested sequences. """
     with pytest.raises(AssertionError) as exc_info:
         assert list(
             parser.generate_commands(
                 yaml.load("""
             - - foreach: my_series:A,B
               - - foreach: my_series:1,2
                 - echo test{{my_series}}
         """)))
コード例 #4
0
 def test_nested_foreach_sequences(self):
     """ Sequences are expanded based using the 'foreach' feature. """
     assert list(
         parser.generate_commands(
             yaml.load("""
         - foreach: my_series:A,B
         - - foreach: 1,2
           - echo test{{my_series}}_{{1,2}}
     """))) == [('echo testA_1', {}), ('echo testA_2', {}),
                ('echo testB_1', {}), ('echo testB_2', {})]
コード例 #5
0
 def test_removes_trailing_newline_from_complex_keys(self):
     """ Check that only valid keywords are used """
     commands = list(
         parser.generate_commands(
             yaml.load("""
         - ? >
               Line 1
               Line 2
           : retries: 1
         """)))
     assert commands == [('Line 1 Line 2', {'retries': 1})]
コード例 #6
0
 def test_badly_formatted_entry(self):
     """ Test that a command object has only one-key """
     with pytest.raises(AssertionError) as exc_info:
         list(
             parser.generate_commands(
                 yaml.load("""
             - key1: 1
               key2: 2
             """)))
     assert "Command has multiple top-level keys: ['key1', 'key2']" in str(
         exc_info.value)
コード例 #7
0
 def test_simple_foreach_sequence(self):
     """ Sequences are repeated for each item in the 'foreach' series. """
     assert list(
         parser.generate_commands(
             yaml.load("""
         - foreach: my_series:A,B
         - echo test{{my_series}}_{{x,y}}
         - echo test2{{my_series}}
     """))) == [('echo testA_x', {}), ('echo testA_y', {}),
                ('echo test2A', {}), ('echo testB_x', {}),
                ('echo testB_y', {}), ('echo test2B', {})]
コード例 #8
0
 def test_foreach_in_non_first_position_raises_error(self):
     """ 'Foreach' can only be specified at the beginning of a sequence. """
     with pytest.raises(AssertionError) as exc_info:
         list(
             parser.generate_commands(
                 yaml.load("""
             - something
             - foreach: [A,B]
             """)))
     assert (
         "'foreach' may only be specified at the beginning of a sequence"
         in str(exc_info.value))
コード例 #9
0
 def test_foreach_series_with_features(self):
     """ Sequences are repeated for each item in the 'foreach' series. """
     assert list(
         parser.generate_commands(
             yaml.load("""
         - foreach: [A,B]
         - echo test{{A,B}}:
             depends_on: pre{{A,B}}
     """))) == [('echo testA', {
                 'depends_on': 'preA'
             }), ('echo testB', {
                 'depends_on': 'preB'
             })]
コード例 #10
0
 def test_foreach_series_with_integer_feature_values(self):
     """ Sequences are repeated for each item in the 'foreach' series. """
     assert list(
         parser.generate_commands(
             yaml.load("""
         - foreach: [A,B]
         - echo test{{A,B}}:
             retries: 1
     """))) == [('echo testA', {
                 'retries': 1
             }), ('echo testB', {
                 'retries': 1
             })]
コード例 #11
0
def parse_command(command):
    return list(parser.generate_commands([command]))