def test_load_json(): with temporary_dir() as td: clusters_json = os.path.join(td, 'clusters.json') # as dict with open(clusters_json, 'w') as fp: fp.write(json.dumps(CLUSTERS)) validate_loaded_clusters(Clusters.from_file(clusters_json)) # as list with open(clusters_json, 'w') as fp: fp.write(json.dumps(CLUSTERS.values())) validate_loaded_clusters(Clusters.from_file(clusters_json))
def test_load_json(): with temporary_dir() as td: clusters_json = os.path.join(td, 'clusters.json') # as dict with open(clusters_json, 'w') as fp: fp.write(json.dumps(CLUSTERS)) validate_loaded_clusters(Clusters.from_file(clusters_json)) # as list with open(clusters_json, 'w') as fp: fp.write(json.dumps(CLUSTERS.values())) validate_loaded_clusters(Clusters.from_file(clusters_json))
def test_load_invalid_syntax(): with temporary_dir() as td: # bad json clusters_json = os.path.join(td, 'clusters.json') with open(clusters_json, 'w') as fp: fp.write('This is not json') with pytest.raises(Clusters.ParseError): Clusters.from_file(clusters_json) # bad yaml clusters_yml = os.path.join(td, 'clusters.yml') with open(clusters_yml, 'w') as fp: fp.write('L{}L') with pytest.raises(Clusters.ParseError): Clusters.from_file(clusters_yml) # bad layout clusters_yml = os.path.join(td, 'clusters.yml') with open(clusters_yml, 'w') as fp: fp.write('just a string') with pytest.raises(Clusters.ParseError): Clusters.from_file(clusters_yml) # not a dict clusters_json = os.path.join(td, 'clusters.json') with open(clusters_json, 'w') as fp: fp.write(json.dumps({'cluster1': ['not', 'cluster', 'values']})) with pytest.raises(Clusters.ParseError): Clusters.from_file(clusters_json)
def test_load_invalid_syntax(): with temporary_dir() as td: # bad json clusters_json = os.path.join(td, 'clusters.json') with open(clusters_json, 'w') as fp: fp.write('This is not json') with pytest.raises(Clusters.ParseError): Clusters.from_file(clusters_json) # bad yaml clusters_yml = os.path.join(td, 'clusters.yml') with open(clusters_yml, 'w') as fp: fp.write('L{}L') with pytest.raises(Clusters.ParseError): Clusters.from_file(clusters_yml) # bad layout clusters_yml = os.path.join(td, 'clusters.yml') with open(clusters_yml, 'w') as fp: fp.write('just a string') with pytest.raises(Clusters.ParseError): Clusters.from_file(clusters_yml) # not a dict clusters_json = os.path.join(td, 'clusters.json') with open(clusters_json, 'w') as fp: fp.write(json.dumps({'cluster1': ['not', 'cluster', 'values']})) with pytest.raises(Clusters.ParseError): Clusters.from_file(clusters_json)
def test_load_yaml(): with temporary_dir() as td: clusters_yml = os.path.join(td, 'clusters.yml') with open(clusters_yml, 'w') as fp: fp.write(TEST_YAML) validate_loaded_clusters(Clusters.from_file(clusters_yml))
def test_load_yaml(): with temporary_dir() as td: clusters_yml = os.path.join(td, 'clusters.yml') with open(clusters_yml, 'w') as fp: fp.write(TEST_YAML) validate_loaded_clusters(Clusters.from_file(clusters_yml))