this repo has no description
1// Copyright (c) Facebook, Inc. and its affiliates. (http://www.facebook.com)
2#include <fcntl.h>
3#include <unistd.h>
4
5#include "gtest/gtest.h"
6
7#include "builtins.h"
8#include "file.h"
9#include "test-utils.h"
10
11namespace py {
12namespace testing {
13using UnderPathModuleTest = RuntimeFixture;
14
15TEST_F(UnderPathModuleTest, PathIsdirWithFileReturnsFalse) {
16 TemporaryDirectory tempdir;
17 std::string file_path = tempdir.path + "foo.py";
18 writeFile(file_path, "");
19
20 HandleScope scope(thread_);
21 const char* path = file_path.c_str();
22 Object path_obj(&scope, runtime_->newStrFromCStr(path));
23 EXPECT_EQ(runBuiltin(FUNC(_path, isdir), path_obj), Bool::falseObj());
24}
25
26TEST_F(UnderPathModuleTest, PathIsdirWithDirectoryReturnsTrue) {
27 TemporaryDirectory tempdir;
28
29 HandleScope scope(thread_);
30 const char* path = tempdir.path.c_str();
31 Object path_obj(&scope, runtime_->newStrFromCStr(path));
32 EXPECT_EQ(runBuiltin(FUNC(_path, isdir), path_obj), Bool::trueObj());
33}
34
35TEST_F(UnderPathModuleTest, PathIsfileWithFileReturnsTrue) {
36 TemporaryDirectory tempdir;
37 std::string file_path = tempdir.path + "foo.py";
38 writeFile(file_path, "");
39
40 HandleScope scope(thread_);
41 const char* path = file_path.c_str();
42 Object path_obj(&scope, runtime_->newStrFromCStr(path));
43 EXPECT_EQ(runBuiltin(FUNC(_path, isfile), path_obj), Bool::trueObj());
44}
45
46TEST_F(UnderPathModuleTest, PathIsfileWithDirectoryReturnsFalse) {
47 TemporaryDirectory tempdir;
48
49 HandleScope scope(thread_);
50 const char* path = tempdir.path.c_str();
51 Object path_obj(&scope, runtime_->newStrFromCStr(path));
52 EXPECT_EQ(runBuiltin(FUNC(_path, isfile), path_obj), Bool::falseObj());
53}
54
55} // namespace testing
56} // namespace py