Skip to content

Commit b9feee9

Browse files
committed
#16: Added tests for notice_text() and license_text()
Added description for notice_text()
1 parent 2ebc3e7 commit b9feee9

File tree

7 files changed

+69
-0
lines changed

7 files changed

+69
-0
lines changed

about.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -559,6 +559,10 @@ def license_text(self):
559559
return ""
560560

561561
def notice_text(self):
562+
'''
563+
Returns the text in a notice file if the notice_file field exists in a
564+
.ABOUT file and the file that is in the notice_file: field exists
565+
'''
562566
try:
563567
notice_text_path = self.file_fields_locations["notice_file"]
564568
with open(notice_text_path, 'rU') as f:

testdata/attrib/license_text.ABOUT

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
about_resource:license_text_test
2+
name: license extraction
3+
version: beta
4+
notes: this is a test file to see if the license_test() correctly returns the
5+
the text of the file in license_text_file field
6+
license_text_file: license_text.LICENSE
7+
notice_file: notice_text.NOTICE
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Tester holds the copyright for test component. Tester relinquishes copyright of
2+
this software and releases the component to Public Domain.
3+
4+
* Email [email protected] for any questions
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
about_resource:license_text_test
2+
name: license extraction
3+
version: beta
4+
notes: this is a test file to see if the license_test() correctly returns an
5+
of empty string when the license_text_file and notice_file have file values
6+
that do not exist
7+
license_text_file: test.LICENSE
8+
notice_file: test.NOTICE
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
about_resource: no_license_text_field_field
2+
name: license extraction
3+
version: beta
4+
notes: this is a test file to see if the license_test() correctly returns the
5+
the text of the file in license_text_file field

testdata/attrib/notice_text.NOTICE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Test component is released to Public Domain.

tests.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -472,5 +472,45 @@ def test_generate_attribution(self):
472472
result = about_collector.generate_attribution('testdata/attrib/test.template')
473473
self.assertEqual(result, expected)
474474

475+
def test_license_text_extracted_from_license_text_file(self):
476+
expected ='''Tester holds the copyright for test component. Tester relinquishes copyright of
477+
this software and releases the component to Public Domain.
478+
479+
* Email [email protected] for any questions'''
480+
481+
about_file = about.AboutFile('testdata/attrib/license_text.ABOUT')
482+
license_text = about_file.license_text()
483+
self.assertEqual(license_text, expected)
484+
485+
def test_notice_text_extacted_from_notice_text_file(self):
486+
expected ='''Test component is released to Public Domain.'''
487+
about_file = about.AboutFile('testdata/attrib/license_text.ABOUT')
488+
notice_text = about_file.notice_text()
489+
self.assertEqual(notice_text, expected)
490+
491+
def test_license_text_returns_empty_string_when_no_field_present(self):
492+
expected = ''
493+
about_file = about.AboutFile('testdata/attrib/no_text_file_field.ABOUT')
494+
license_text = about_file.license_text()
495+
self.assertEqual(license_text, expected)
496+
497+
def test_notice_text_returns_empty_string_when_no_field_present(self):
498+
expected = ''
499+
about_file = about.AboutFile('testdata/attrib/no_text_file_field.ABOUT')
500+
notice_text = about_file.notice_text()
501+
self.assertEqual(notice_text, expected)
502+
503+
def test_license_text_returns_empty_string_when_ref_file_doesnt_exist(self):
504+
expected = ''
505+
about_file = about.AboutFile('testdata/attrib/missing_notice_license_files.ABOUT')
506+
license_text = about_file.license_text()
507+
self.assertEqual(license_text, expected)
508+
509+
def test_notice_text_returns_empty_string_when_ref_file_doesnt_exist(self):
510+
expected = ''
511+
about_file = about.AboutFile('testdata/attrib/missing_notice_license_files.ABOUT')
512+
notice_text = about_file.notice_text()
513+
self.assertEqual(notice_text, expected)
514+
475515
if __name__ == "__main__":
476516
unittest.main()

0 commit comments

Comments
 (0)