-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_lab4.py
37 lines (32 loc) · 1.55 KB
/
test_lab4.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import datetime
import os
import subprocess
import time
import unittest
class Lab4TestCase(unittest.TestCase):
@classmethod
def setUpClass(cls):
cls.year = 2021
subprocess.run(['make'], capture_output=True)
subprocess.run(['./ext2-create'], capture_output=True)
p = subprocess.run(['dumpe2fs', 'cs111-base.img'], capture_output=True, text=True)
cls.dump_lines = p.stdout.splitlines()
p = subprocess.run(['fsck.ext2', '-f', '-n', 'cs111-base.img'], capture_output=True, text=True)
cls.fsck_lines = p.stdout.splitlines()
p = subprocess.run(['ls', '-f', '-n', 'cs111-base.img'], capture_output=True, text=True)
cls.ls_lines = p.stdout.splitlines()
subprocess.run(['mkdir', 'mnt'], capture_output=True)
subprocess.run(['sudo', 'mount', '-o', 'loop', 'cs111-base.img', 'mnt'])
cls.root_stat = os.lstat('mnt') if os.path.exists('mnt') else None
cls.hello_world_stat = os.lstat('mnt/hello-world') if os.path.exists('mnt/hello-world') else None
cls.hello_stat = os.lstat('mnt/hello') if os.path.exists('mnt/hello') else None
@classmethod
def tearDownClass(cls):
subprocess.run(['sudo', 'umount', 'mnt'])
subprocess.run(['rmdir', 'mnt'], capture_output=True)
subprocess.run(['make', 'clean'], capture_output=True)
def test_hello(self):
self.assertEqual(os.readlink('mnt/hello'), 'hello-world')
def test_hello_world(self):
with open('mnt/hello-world') as f:
self.assertEqual(f.read(), "Hello world\n")