Skip to content

Commit

Permalink
Add analyzed_output property
Browse files Browse the repository at this point in the history
Create a property called analyzed_output in the
 ImageLayer class located in tern/classes/image_layer.py

Resolves tern-tools#445

Signed-off-by: Manaswini Das <[email protected]>
  • Loading branch information
manaswinidas authored and Nisha K committed Sep 26, 2019
1 parent 4138384 commit 7c3bbf2
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
15 changes: 14 additions & 1 deletion tern/classes/image_layer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -47,6 +48,7 @@ def __init__(self, diff_id, tar_file=None, created_by=None):
self.__pkg_format = ''
self.__os_guess = ''
self.__files_analyzed = False
self.__analyzed_output = ''

@property
def diff_id(self):
Expand Down Expand Up @@ -108,6 +110,17 @@ def os_guess(self):
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
Expand All @@ -118,7 +131,7 @@ def files_analyzed(self, x):
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():
Expand Down
5 changes: 5 additions & 0 deletions tests/test_class_image_layer.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ def testInstance(self):
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"
Expand Down

0 comments on commit 7c3bbf2

Please sign in to comment.