|
| 1 | +#!/usr/bin/python |
| 2 | + |
| 3 | +''' |
| 4 | +Test analysis classification functions |
| 5 | +
|
| 6 | +The MIT License (MIT) |
| 7 | +
|
| 8 | +Copyright (c) 2016-2017 Vanessa Sochat |
| 9 | +
|
| 10 | +Permission is hereby granted, free of charge, to any person obtaining a copy |
| 11 | +of this software and associated documentation files (the "Software"), to deal |
| 12 | +in the Software without restriction, including without limitation the rights |
| 13 | +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 14 | +copies of the Software, and to permit persons to whom the Software is |
| 15 | +furnished to do so, subject to the following conditions: |
| 16 | +
|
| 17 | +The above copyright notice and this permission notice shall be included in all |
| 18 | +copies or substantial portions of the Software. |
| 19 | +
|
| 20 | +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 21 | +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 22 | +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 23 | +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 24 | +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 25 | +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 26 | +SOFTWARE. |
| 27 | +
|
| 28 | +''' |
| 29 | + |
| 30 | + |
| 31 | +from numpy.testing import ( |
| 32 | + assert_array_equal, |
| 33 | + assert_almost_equal, |
| 34 | + assert_equal |
| 35 | +) |
| 36 | + |
| 37 | +from singularity.cli import get_image |
| 38 | +import unittest |
| 39 | +import tempfile |
| 40 | +import shutil |
| 41 | +import json |
| 42 | +import os |
| 43 | + |
| 44 | +class TestAnalysisClassify(unittest.TestCase): |
| 45 | + |
| 46 | + def setUp(self): |
| 47 | + self.tmpdir = tempfile.mkdtemp() |
| 48 | + self.container = get_image('docker://ubuntu:16.04') |
| 49 | + self.comparator = get_image('docker://ubuntu:12.04') |
| 50 | + |
| 51 | + def tearDown(self): |
| 52 | + shutil.rmtree(self.tmpdir) |
| 53 | + |
| 54 | + |
| 55 | + def test_get_diff(self): |
| 56 | + print("Testing singularity.analysis.classify.get_diff") |
| 57 | + from singularity.analysis.classify import get_diff |
| 58 | + diff = get_diff(self.container) |
| 59 | + for key in ['.singularity.d', 'lists', 'actions', 'user', 'env']: |
| 60 | + self.assertTrue(key in diff) |
| 61 | + |
| 62 | + |
| 63 | + def test_estimate_os(self): |
| 64 | + print("Testing singularity.analysis.classify.estimate_os") |
| 65 | + from singularity.analysis.classify import estimate_os |
| 66 | + estimated_os = estimate_os(self.container) |
| 67 | + self.assertEqual(estimated_os,'ubuntu:16.10') |
| 68 | + |
| 69 | + |
| 70 | + def test_get_tags(self): |
| 71 | + print("Testing singularity.analysis.classify.get_tags") |
| 72 | + from singularity.analysis.classify import get_tags |
| 73 | + tags = get_tags(self.container) |
| 74 | + |
| 75 | + print("Case 1: Testing that empty OS (with no additions) returns no relevant tags") |
| 76 | + self.assertEqual(estimated_os,'ubuntu:16.10') |
| 77 | + self.assertTrue(len(tags)==0) |
| 78 | + |
| 79 | + |
| 80 | + def test_file_counts(self): |
| 81 | + print("Testing singularity.analysis.classify.file_counts") |
| 82 | + from singularity.analysis.classify import file_counts |
| 83 | + counts = file_counts(self.container) |
| 84 | + |
| 85 | + |
| 86 | + def test_extension_counts(self): |
| 87 | + print("Testing singularity.analysis.classify.extension_counts") |
| 88 | + from singularity.analysis.classify import extension_counts |
| 89 | + counts = extension_counts(self.container) |
| 90 | + self.assertTrue(len(counts)>0) |
| 91 | + |
| 92 | + |
| 93 | + |
| 94 | +if __name__ == '__main__': |
| 95 | + unittest.main() |
0 commit comments