Example #1
0
 def test_yamlprocess_init(self):
     yp = val.YAMLProcessor()
     assert yp.loaded == False
     assert yp.data == []
     assert yp.doclines == []
     assert yp._clean
     assert yp.ymlfile is None
Example #2
0
def testYAMLProcessorProcess():
    ymlproc = val.YAMLProcessor()
    ymlproc.process(os.path.join(DATA_PATH, "testValidCmd1.yaml"))

    # check the document lines are correct
    doclines = [85]
    assert doclines == ymlproc.doclines
Example #3
0
    def test_empty_file_process(self):
        open(self.test_yaml_file, 'w').close()

        yp = val.YAMLProcessor(clean=False)
        nose.tools.assert_raises(util.YAMLError, yp.process,
                                 self.test_yaml_file)

        os.remove(self.test_yaml_file)
Example #4
0
    def test_empty_file_process(self):
        open(self.test_yaml_file, "w").close()

        yp = val.YAMLProcessor(clean=False)
        with pytest.raises(util.YAMLError):
            yp.process(self.test_yaml_file)

        os.remove(self.test_yaml_file)
Example #5
0
    def test_basic_process_seq_name_strip(self):
        yaml_docs = (' - !bar\n' ' - blah\n')

        with open(self.test_yaml_file, 'w') as out:
            out.write(yaml_docs)

        yp = val.YAMLProcessor(clean=False)
        out = yp.process(self.test_yaml_file)

        assert "bar:" in out
        os.remove(self.test_yaml_file)
Example #6
0
    def test_basic_process_doc_object_name_strip(self):
        yaml_docs = ('a: hello\n' '--- !foo\n' 'b: goodbye\n')

        with open(self.test_yaml_file, 'w') as out:
            out.write(yaml_docs)

        yp = val.YAMLProcessor(clean=False)
        out = yp.process(self.test_yaml_file)

        assert len(yp.doclines) == 2
        assert yp.doclines == [1, 3]
        assert '!foo' not in out
        os.remove(self.test_yaml_file)
Example #7
0
    def test_yaml_load_without_clean(self):
        yaml_docs = ('---\n' 'a: hello\n' '---\n' 'b: goodbye\n')

        with open(self.test_yaml_file, 'wb') as out:
            out.write(yaml_docs)

        yp = val.YAMLProcessor(clean=False)
        yp.load(self.test_yaml_file)
        assert len(yp.data) == 2
        assert yp.data[0]['a'] == 'hello'
        assert yp.data[1]['b'] == 'goodbye'

        os.remove(self.test_yaml_file)
Example #8
0
    def test_yaml_load_without_clean(self):
        yaml_docs = "---\n" "a: hello\n" "---\n" "b: goodbye\n"

        with open(self.test_yaml_file, "wt") as out:
            out.write(yaml_docs)

        yp = val.YAMLProcessor(clean=False)
        yp.load(self.test_yaml_file)
        assert len(yp.data) == 2
        assert yp.data[0]["a"] == "hello"
        assert yp.data[1]["b"] == "goodbye"

        os.remove(self.test_yaml_file)
Example #9
0
    def test_invalid_yaml_load(self):
        yaml_docs = """
        ---
        a: these newlines and white space break stuff
        ---
        b: processing wont even get here
        """
        with open(self.test_yaml_file, 'wb') as out:
            out.write(yaml_docs)

        yp = val.YAMLProcessor(clean=False)
        nose.tools.assert_raises(util.YAMLError, yp.load, self.test_yaml_file)

        os.remove(self.test_yaml_file)
Example #10
0
    def test_invalid_yaml_process(self):
        yaml_docs = """
        ---
        a: these newlines and white space break stuff
        ---
        b: processing wont even get here
        """
        open(self.test_yaml_file, 'w').close()

        yp = val.YAMLProcessor(clean=False)
        nose.tools.assert_raises(
            IOError, yp.process, '/tmp/thisFileDoesntExistAndWillCauseAnError')

        os.remove(self.test_yaml_file)
Example #11
0
    def test_invalid_yaml_process(self):
        yaml_docs = """
        ---
        a: these newlines and white space break stuff
        ---
        b: processing wont even get here
        """
        open(self.test_yaml_file, "w").close()

        yp = val.YAMLProcessor(clean=False)
        with pytest.raises(IOError):
            yp.process("/tmp/thisFileDoesntExistAndWillCauseAnError")

        os.remove(self.test_yaml_file)
Example #12
0
def testYAMLProcesserLoad():
    ymlproc = val.YAMLProcessor()

    # Test bad path
    try:
        ymlfile = os.path.join('invalid', 'file', 'path.yaml')
        ymlproc.load(ymlfile)
        assert False
    except IOError:
        assert True
        assert not ymlproc.loaded

    # Test valid yaml
    ymlproc.load(os.path.join(DATA_PATH, "testValidCmd1.yaml"))

    assert ymlproc.data is not None
    assert ymlproc.loaded
Example #13
0
 def test_yaml_load_with_clean(self, process_mock):
     yp = val.YAMLProcessor()
     yp.load()
     assert process_mock.called
     assert yp.loaded
Example #14
0
 def test_ymlfile_setter(self, yaml_load_mock):
     yp = val.YAMLProcessor()
     assert yaml_load_mock.call_count == 0
     ymlfile = 'something that is not None'
     yp.load(ymlfile)
     assert yaml_load_mock.call_count == 1