diff --git a/README.md b/README.md index 965405d..24c9138 100644 --- a/README.md +++ b/README.md @@ -44,6 +44,14 @@ print(machineid.hashed_id('myappid')) print(machineid.hashed_id()) ``` +## Testing + +To run tests, invoke `unittest`: + +```bash +python3 -m unittest +``` + ## Thanks Special thanks to Denis Brodbeck for his Go package, [`machineid`](https://github.com/denisbrodbeck/machineid). diff --git a/machineid/__init__.py b/machineid/__init__.py index 7bf12c1..4933930 100644 --- a/machineid/__init__.py +++ b/machineid/__init__.py @@ -86,7 +86,9 @@ def id(winregistry: bool = True) -> str: mountinfo = __read__('/proc/self/mountinfo') if mountinfo: if 'docker' in mountinfo: - id = __exec__("grep 'systemd' /proc/self/mountinfo | cut -d/ -f3") + id = __exec__("grep '/data/docker/containers' /proc/self/mountinfo | cut -d/ -f5") + if not id: + id = __exec__("grep '/var/lib/docker/containers' /proc/self/mountinfo | cut -d/ -f6") if not id: if 'microsoft' in uname().release: # wsl id = __exec__("powershell.exe -ExecutionPolicy bypass -command '(Get-CimInstance -Class Win32_ComputerSystemProduct).UUID'") diff --git a/tests/__init__.py b/tests/__init__.py index 2684511..d226c58 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -5,15 +5,15 @@ class TestMachineId(unittest.TestCase): def test_hashed_id(self): - self.assertTrue(isinstance(machineid.hashed_id(), str)) - self.assertTrue(len(machineid.hashed_id()) > 0) - self.assertTrue(machineid.hashed_id('foo') != machineid.hashed_id('bar')) - self.assertTrue(machineid.hashed_id('foo') != machineid.hashed_id()) + self.assertIsInstance(machineid.hashed_id(), str) + self.assertGreater(len(machineid.hashed_id()), 0) + self.assertNotEqual(machineid.hashed_id('foo'), machineid.hashed_id('bar')) + self.assertNotEqual(machineid.hashed_id('foo'), machineid.hashed_id()) def test_id(self): - self.assertTrue(isinstance(machineid.id(), str)) - self.assertTrue(len(machineid.id()) > 0) - self.assertTrue(machineid.id() != machineid.hashed_id()) + self.assertIsInstance(machineid.id(), str) + self.assertGreater(len(machineid.id()), 0) + self.assertNotEqual(machineid.id(), machineid.hashed_id()) if __name__ == '__main__': - unittest.main() \ No newline at end of file + unittest.main()