def test_materialize(self) -> None: f = MagicMock(return_value="test") x = LazyPath(f) f.assert_not_called() p = os.fspath(x) f.assert_called() self.assertEqual(p, "test") p = os.fspath(x) # should only be called once f.assert_called_once() self.assertEqual(p, "test")
def test_getitem(self) -> None: x = LazyPath(lambda: "abc") with self.assertRaises(TypeError): x[0] _ = os.fspath(x) self.assertEqual(x[0], "a")
def test_PathManager(self) -> None: x = LazyPath(lambda: "./") output = PathManager.ls(x) # pyre-ignore output_gt = PathManager.ls("./") self.assertEqual(sorted(output), sorted(output_gt))
def test_getattr(self) -> None: x = LazyPath(lambda: "abc") with self.assertRaises(AttributeError): x.startswith("ab") _ = os.fspath(x) self.assertTrue(x.startswith("ab"))
def test_join(self) -> None: f = MagicMock(return_value="test") x = LazyPath(f) p = os.path.join(x, "a.txt") f.assert_called_once() self.assertEqual(p, "test/a.txt")
def test_PathManager(self): x = LazyPath(lambda: "./") output = PathManager.ls(x) output_gt = PathManager.ls("./") self.assertEqual(sorted(output), sorted(output_gt))