Repository: vmware/tern (python)

Issue:
Create an analyzed_output property for each layer with appropriate tests
***Description***
Create a property called `analyzed_output` in the ImageLayer class located in `tern/classes/image_layer.py`.

***Implementation***
In `tern/classes/image_layer.py`:

1. Add `analyzed_output` to class docstring under class ImageLayer:
`analyzed_output: the result of the file analysis`.
2. Add the property to `__init__` function and set it to an empty string.
3. Add a getter and setter. The setter should check if the input is a string and if not, then raise a ValueError with a message like "analyzed_output should be a string"

In `tests/test_class_image_layer.py`, add tests for files_analyzed in `testInstance`:
1. Test if the default value is and empty string.
2. Test if the value can be set to any string.
3. Test if a ValueError is raised if you set it to an `int`.

References
Look in tern/classes/image_layer.py and tests/test_class_image_layer.py to see examples of how to implement this.

Super Issues
#284

Pull request description:
Add analyzed_output property
Create a property called analyzed_output in the
 ImageLayer class located in tern/classes/image_layer.py

Resolves #445

Signed-off-by: Manaswini Das <dasmanaswini10@gmail.com>

Patch:
diff --git a/tern/classes/image_layer.py b/tern/classes/image_layer.py
index e859152..77e759e 100644
--- a/tern/classes/image_layer.py
+++ b/tern/classes/image_layer.py
@@ -29,6 +29,7 @@ class ImageLayer:
         import_str: The string from a build tool (like a Dockerfile) that
         created this layer by importing it from another image
         files_analyzed: whether the files in this layer are analyzed or not
+        analyzed_output: the result of the file analysis
     methods:
         add_package: adds a package to the layer
         remove_package: removes a package from the layer
@@ -47,6 +48,7 @@ class ImageLayer:
         self.__pkg_format = ''
         self.__os_guess = ''
         self.__files_analyzed = False
+        self.__analyzed_output = ''
 
     @property
     def diff_id(self):
@@ -108,6 +110,17 @@ class ImageLayer:
     def os_guess(self, os_guess):
         self.__os_guess = os_guess
 
+    @property
+    def analyzed_output(self):
+        return self.__analyzed_output
+
+    @analyzed_output.setter
+    def analyzed_output(self, analyzed_output):
+        if isinstance(analyzed_output, str):
+            self.__analyzed_output = analyzed_output
+        else:
+            raise ValueError('analyzed_output should be a string')
+    
     @property
     def files_analyzed(self):
         return self.__files_analyzed
@@ -118,7 +131,7 @@ class ImageLayer:
             self.__files_analyzed = x
         else:
             raise ValueError('files_analyzed should be boolean')
-    
+
     def add_package(self, package):
         if isinstance(package, Package):
             if package.name not in self.get_package_names():


Test patch:
diff --git a/tests/test_class_image_layer.py b/tests/test_class_image_layer.py
index 259ffdd..8946259 100644
--- a/tests/test_class_image_layer.py
+++ b/tests/test_class_image_layer.py
@@ -39,6 +39,11 @@ class TestClassImageLayer(unittest.TestCase):
         self.assertTrue(self.layer.files_analyzed)
         self.assertRaises(ValueError, setattr, self.layer,
                           'files_analyzed', 'some string')
+        self.assertEqual("", self.layer.analyzed_output)
+        self.layer.analyzed_output = 'some string'
+        self.assertEqual(self.layer.analyzed_output, 'some string')
+        self.assertRaises(ValueError, setattr, self.layer,
+                          'analyzed_output', 123)
 
     def testAddPackage(self):
         err = "Object type String, should be Package"