Esempio n. 1
0
    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")
Esempio n. 2
0
 def test_getitem(self) -> None:
     x = LazyPath(lambda: "abc")
     with self.assertRaises(TypeError):
         x[0]
     _ = os.fspath(x)
     self.assertEqual(x[0], "a")
Esempio n. 3
0
 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))
Esempio n. 4
0
 def test_getattr(self) -> None:
     x = LazyPath(lambda: "abc")
     with self.assertRaises(AttributeError):
         x.startswith("ab")
     _ = os.fspath(x)
     self.assertTrue(x.startswith("ab"))
Esempio n. 5
0
 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")
Esempio n. 6
0
 def test_PathManager(self):
     x = LazyPath(lambda: "./")
     output = PathManager.ls(x)
     output_gt = PathManager.ls("./")
     self.assertEqual(sorted(output), sorted(output_gt))