Home | History | Annotate | Download | only in tests
      1 #!/usr/bin/env python
      2 #
      3 #   Copyright 2017 - The Android Open Source Project
      4 #
      5 #   Licensed under the Apache License, Version 2.0 (the "License");
      6 #   you may not use this file except in compliance with the License.
      7 #   You may obtain a copy of the License at
      8 #
      9 #       http://www.apache.org/licenses/LICENSE-2.0
     10 #
     11 #   Unless required by applicable law or agreed to in writing, software
     12 #   distributed under the License is distributed on an "AS IS" BASIS,
     13 #   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     14 #   See the License for the specific language governing permissions and
     15 #   limitations under the License.
     16 
     17 import unittest
     18 
     19 from metrics import disk_metric
     20 from tests import fake
     21 
     22 
     23 class DiskMetricTest(unittest.TestCase):
     24     """Class for testing DiskMetric."""
     25 
     26     def test_return_total_used_avail_percent(self):
     27         # Create sample stdout string ShellCommand.run() would return
     28         stdout_string = '/dev/sda 57542652 18358676 ' '36237928  34% /'
     29         FAKE_RESULT = fake.FakeResult(stdout=stdout_string)
     30         fake_shell = fake.MockShellCommand(fake_result=FAKE_RESULT)
     31         metric_obj = disk_metric.DiskMetric(shell=fake_shell)
     32 
     33         expected_result = {
     34             disk_metric.DiskMetric.TOTAL: 57542652,
     35             disk_metric.DiskMetric.USED: 18358676,
     36             disk_metric.DiskMetric.AVAIL: 36237928,
     37             disk_metric.DiskMetric.PERCENT_USED: 34
     38         }
     39         self.assertEqual(expected_result, metric_obj.gather_metric())
     40 
     41 
     42 if __name__ == '__main__':
     43     unittest.main()
     44