Example #1
0
 def test_b_function_correct_output_free_space(self):
     """[Lab 3] - [Investigation 2] - [Part 2] - functions & subprocess - Test output shows free space of root"""
     # Try to import before testing
     try:
         import lab3d as lab3dStudent
     except:
         self.fail(
             'lab3d.py contains errors(HINT: run the function and fix errors'
         )
     p = subprocess.Popen(["df -h | grep '/$' | awk '{print $4}'"],
                          stdout=subprocess.PIPE,
                          stdin=subprocess.PIPE,
                          stderr=subprocess.PIPE,
                          shell=True)
     stdout, err = p.communicate()
     try:
         error_output = 'wrong output(HINT: show root directory free space only)'
         self.assertEqual(stdout.decode('utf-8').strip(),
                          lab3dStudent.free_space().decode('utf-8').strip(),
                          msg=error_output)
     except AttributeError:
         error_output = 'did you already decode utf-8(HINT: you will need to do this later)'
         # If they already decoded the string an error will be raised this except fixes problem
         self.assertEqual(stdout.decode('utf-8').strip(),
                          lab3dStudent.free_space().strip(),
                          msg=error_output)
Example #2
0
 def test_a_function_free_space(self):
     """[Lab 3] - [Investigation 2] - [Part 2] - functions & subprocess - Test function succeeds with 0 arguments"""
     # Try to import before testing
     try:
         import lab3d as lab3dStudent
     except:
         self.fail(
             'lab3d.py contains errors(HINT: run the function and fix errors'
         )
     # Test function
     try:
         lab3dStudent.free_space()
     except:
         self.fail(
             'free_space() function contains errors(HINT: run the function and fix errors'
         )
Example #3
0
 def test_d_function_strip_free_space(self):
     """[Lab 3] - [Investigation 2] - [Part 2] - functions & subprocess - strip the new line character with string.strip() successfully """
     # Try to import before testing
     try:
         import lab3d as lab3dStudent
     except:
         self.fail(
             'lab3d.py contains errors(HINT: run the function and fix errors'
         )
     p = subprocess.Popen(["df -h | grep '/$' | awk '{print $4}'"],
                          stdout=subprocess.PIPE,
                          stdin=subprocess.PIPE,
                          stderr=subprocess.PIPE,
                          shell=True)
     stdout, err = p.communicate()
     error_output = 'output did not strip new line character(HINT: use string.strip() to remove)'
     self.assertNotEqual(stdout.decode('utf-8'),
                         lab3dStudent.free_space(),
                         msg=error_output)
Example #4
0
 def test_c_function_decode_free_space(self):
     """[Lab 3] - [Investigation 2] - [Part 2] - functions & subprocess - decode to utf-8 with string.decode('utf-8') successfully"""
     # Try to import before testing
     try:
         import lab3d as lab3dStudent
     except:
         self.fail(
             'lab3d.py contains errors(HINT: run the function and fix errors'
         )
     p = subprocess.Popen(["df -h | grep '/$' | awk '{print $4}'"],
                          stdout=subprocess.PIPE,
                          stdin=subprocess.PIPE,
                          stderr=subprocess.PIPE,
                          shell=True)
     stdout, err = p.communicate()
     error_output = 'output did not decode to utf-8(HINT: use string.decode(\'utf-8\') to decode)'
     # encode is used to turn unicode strings into bytes, decode turns bytes into unicode strings
     self.assertEqual(type(stdout.decode('utf-8')),
                      type(lab3dStudent.free_space()),
                      msg=error_output)
Example #5
0
import subprocess
import lab3d
lab3d.free_space()