Skip to content
This repository was archived by the owner on Oct 1, 2025. It is now read-only.

Conversation

@XuefengHuang
Copy link

I add some unit tests to check if these functions work fine and results are correct in build_component.py. I add cloning and copying of seattlelib_v2 repo because I need extra files to test process_mix() function.
I have tested them on Mac OS X system. There is my test result:

172-16-21-124:~ Xuefeng$ git clone https://github.com/XuefengHuang/common -b unittests
fatal: destination path 'common' already exists and is not an empty directory.
172-16-21-124:~ Xuefeng$ git clone https://github.com/XuefengHuang/common -b unittests
Cloning into 'common'...
remote: Counting objects: 252, done.
remote: Compressing objects: 100% (146/146), done.
remote: Total 252 (delta 123), reused 206 (delta 98)
Receiving objects: 100% (252/252), 64.47 KiB | 0 bytes/s, done.
Resolving deltas: 100% (123/123), done.
Checking connectivity... done.
172-16-21-124:~ Xuefeng$ cd common/scripts
172-16-21-124:scripts Xuefeng$ python initialize.py
Checking out repo from https://github.com/SeattleTestbed/common ...
Done!
Checking out repo from https://github.com/SeattleTestbed/utf ...
Done!
Checking out repo from https://github.com/SeattleTestbed/seattlelib_v2 ...
Done!
172-16-21-124:scripts Xuefeng$ python build.py -t
Building into /Users/huangxuefeng/common/RUNNABLE
Done building!
172-16-21-124:scripts Xuefeng$ cd ../runnable
172-16-21-124:runnable Xuefeng$ python utf.py -a
Testing module: common
    Running: ut_common_copyfilessubdir.py                       [ PASS ]
    Running: ut_common_copytotarget.py                          [ PASS ]
    Running: ut_common_copytreetotarget.py                      [ PASS ]
    Running: ut_common_helpexit.py                              [ PASS ]
    Running: ut_common_processmix.py                            [ PASS ]
    Running: ut_common_replacestring.py                         [ PASS ]
    Running: ut_common_test_file.py                             [ PASS ]

The unit test check if copy_to_target(file_expr, target) works fine.
The unit test checks if copy_tree_to_target(source, target, ignore=None)
works fine.
The unit test checks if build_component.py can copy files to subdirectories of the build target dir.
The unit test checks if help_exit(errMsg, parser) works fine.
The unit test checks if replace_string(old_string, new_string, file_name_pattern="*") works fine.
The unit test checks if build_component.py works fine.
The unit test checks if process_mix function works fine.
Added a pattern of the file name arg to test if this function can reduce the number of files we look at.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest to refactor this to

  • Build a dummy component specific to this unit test,
  • which has a separate build config,
  • and instead of re-reading the build config, compare the resulting file list after building with a hardcoded file list.

This avoids testing the correctness of a function (reading in the build config in this case) using the same function (i.e. the code below this comment, copied in from build_component.py)

I build a dummy component specific to this unit test which has a separate build config, and instead of re-reading the build config, compare the resulting file list after building with a hardcoded file list.
In the past, it only can delete one  .DS_Store. If there are more than one .DS_Store, it cannot delete them all. Now I use for loop to fix it.
Using two spaces per indent level instead of tab.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants