def test_locate_imported_file(self): compiler = LESS() with patch("os.path.exists") as mocked_os_path_exist: root = os.path.dirname(__file__) existing_files = set() for f in ("A/B.less", "D.less"): existing_files.add(os.path.join(root, "static", normalize_path(f))) mocked_os_path_exist.side_effect = lambda x: x in existing_files self.assertEqual( compiler.locate_imported_file("A", "B.less"), "A/B.less" ) self.assertEqual( compiler.locate_imported_file("E", "../D"), "D.less" ) self.assertEqual( compiler.locate_imported_file("E", "../A/B.less"), "A/B.less" ) self.assertEqual( compiler.locate_imported_file("", "D.less"), "D.less" ) self.assertRaises( StaticCompilationError, lambda: compiler.locate_imported_file("", "Z.less") )
def test_locate_imported_file(self): compiler = LESS() with patch("os.path.exists") as mocked_os_path_exist: existing_files = set() for f in ("A/B.less", "D.less"): existing_files.add(os.path.join(STATIC_ROOT, f)) mocked_os_path_exist.side_effect = lambda x: x in existing_files self.assertEqual( compiler.locate_imported_file("A", "B.less"), "A/B.less" ) self.assertEqual( compiler.locate_imported_file("E", "../D"), "D.less" ) self.assertEqual( compiler.locate_imported_file("E", "../A/B.less"), "A/B.less" ) self.assertEqual( compiler.locate_imported_file("", "D.less"), "D.less" ) self.assertRaises( StaticCompilationError, lambda: compiler.locate_imported_file("", "Z.less") )
def test_locate_imported_file(self): compiler = LESS() with patch("os.path.exists") as mocked_os_path_exist: root = os.path.dirname(__file__) existing_files = set() for f in ("A/B.less", "D.less"): existing_files.add( os.path.join(root, "static", normalize_path(f))) mocked_os_path_exist.side_effect = lambda x: x in existing_files self.assertEqual(compiler.locate_imported_file("A", "B.less"), "A/B.less") self.assertEqual(compiler.locate_imported_file("E", "../D"), "D.less") self.assertEqual(compiler.locate_imported_file("E", "../A/B.less"), "A/B.less") self.assertEqual(compiler.locate_imported_file("", "D.less"), "D.less") self.assertRaises( StaticCompilationError, lambda: compiler.locate_imported_file("", "Z.less"))
def test_locate_imported_file(monkeypatch): compiler = LESS() root = os.path.dirname(__file__) existing_files = set() for f in ("A/B.less", "D.less"): existing_files.add(os.path.join(root, "static", normalize_path(f))) monkeypatch.setattr("os.path.exists", lambda path: path in existing_files) assert compiler.locate_imported_file("A", "B.less") == "A/B.less" assert compiler.locate_imported_file("E", "../D") == "D.less" assert compiler.locate_imported_file("E", "../A/B.less") == "A/B.less" assert compiler.locate_imported_file("", "D.less") == "D.less" with pytest.raises(StaticCompilationError): compiler.locate_imported_file("", "Z.less")