def test_no_implicit_numbers(): assert dumbyaml.load("x: 3.5") == {"x": "3.5", } assert dumbyaml.load("x: +3.5") == {"x": "+3.5", } assert dumbyaml.load("x: +1") == {"x": "+1", } assert dumbyaml.load("x: 0") == {"x": "0", } assert yaml.load("x: 3.5") == {"x": 3.5, } assert yaml.load("x: 0") == {"x": 0, }
def test_flow_style_disallowed(): with pytest.raises(dumbyaml.FlowMappingDisallowed): dumbyaml.load("x: {a: 1, b: 2}") assert yaml.load("x: {a: 1, b: 2}") == { "x": { "a": 1, "b": 2 }, }
def test_no_implicit_nulls(): assert dumbyaml.load("x:") == { "x": "", } assert dumbyaml.load("x: null") == { "x": "null", } assert yaml.load("x:") == { "x": None, } assert yaml.load("x: null") == { "x": None, }
def test_no_implicit_bools(): assert dumbyaml.load("x: yes") == { "x": "yes", } assert dumbyaml.load("x: NO") == { "x": "NO", } assert dumbyaml.load("x: false") == { "x": "false", } assert yaml.load("x: yes") == { "x": True, } assert yaml.load("x: false") == { "x": False, }
def test_no_implicit_numbers(): assert dumbyaml.load("x: 3.5") == { "x": "3.5", } assert dumbyaml.load("x: +3.5") == { "x": "+3.5", } assert dumbyaml.load("x: +1") == { "x": "+1", } assert dumbyaml.load("x: 0") == { "x": "0", } assert yaml.load("x: 3.5") == { "x": 3.5, } assert yaml.load("x: 0") == { "x": 0, }
def main(): """ This is the module's main function. It works, but it needs a little refactoring """ # We'll start by trying to load the configuration file try: # First we find out the current directory current_dir = path.dirname(path.abspath(__file__)) # Then we append our the configuration filename to it, creating the # configuration file's path config_path = path.join(current_dir, 'config.yaml') # Finally, we open the file, read its contents and load it as a YAML file config = yaml.load(open(config_path).read()) # If we fail to load the config file except FileNotFoundError: print( "Sorry, I could not read the configuration file!\n" + "Please, make sure there is a valid config.yaml file at {dirname}" .format(dirname=current_dir) ) exit(1) except YAMLError as yaml_error: print( "Sorry, I did find a file at {configpath} but it does not " + "seem to be a valid YAML file.\nAnyway, here's the error I got:\n\n\t" + str(yaml_error) ) exit(1) apis = config['APIs'] # For each API for api in apis.keys(): # Load the endpoints api = str(api) endpoints = list(apis[api]) # For each endpoint for endpoint in endpoints: endpoint = str(endpoint) test_endpoint(api, endpoint, config)
def test_flow_style_disallowed(): with pytest.raises(dumbyaml.FlowMappingDisallowed): dumbyaml.load("x: {a: 1, b: 2}") assert yaml.load("x: {a: 1, b: 2}") == {"x": {"a": 1, "b": 2}, }
def test_node_anchors_and_references_disallowed(): with pytest.raises(dumbyaml.AnchorTokenDisallowed): assert dumbyaml.load("x: &x 12\ny: *x\n") with pytest.raises(dumbyaml.AnchorTokenDisallowed): assert dumbyaml.load("x: &x\n") assert yaml.load("x: &x 12\ny: *x\n") == {'x': 12, 'y': 12}
def test_tag_token_disallowed(): with pytest.raises(dumbyaml.TagTokenDisallowed): assert dumbyaml.load("""x: !!bool "true"\n""") assert yaml.load("""x: !!bool "true"\n""") == {"x": True}
def test_no_implicit_nulls(): assert dumbyaml.load("x:") == {"x": "", } assert dumbyaml.load("x: null") == {"x": "null", } assert yaml.load("x:") == {"x": None, } assert yaml.load("x: null") == {"x": None, }
def test_no_implicit_bools(): assert dumbyaml.load("x: yes") == {"x": "yes", } assert dumbyaml.load("x: NO") == {"x": "NO", } assert dumbyaml.load("x: false") == {"x": "false", } assert yaml.load("x: yes") == {"x": True, } assert yaml.load("x: false") == {"x": False, }